Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:47:12+00:00 2026-06-14T05:47:12+00:00

In Farseer XNA4.0 C# Physics engine based on Box2D if i use BodyFactory.CreateRectangle(world, w,

  • 0

In Farseer XNA4.0 C# Physics engine based on Box2D

if i use BodyFactory.CreateRectangle(world, w, h, density, new Vector2(x, y)); method to create a body

how can i get the width and height back from the body?

currently im saving the width and height but im wondering if it can be retrieved from a fixture or shape or something. have made some attempts but to no avail. it would save me two floats per entity that im creating.

thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:47:14+00:00Added an answer on June 14, 2026 at 5:47 am

    Ill preface this by saying i’ve never used Farseer, but looking at the class definitions, it doesn’t look like there’s a simple way to get what you want. If you look at the BodyFactory.CreateRectangle method, it doesn’t store directly the Height or Width values:

        public static Body CreateRectangle(World world, float width, float height, float density, Vector2 position,
                                           object userData)
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Width must be more than 0 meters");
    
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Height must be more than 0 meters");
    
            Body newBody = CreateBody(world, position);
            Vertices rectangleVertices = PolygonTools.CreateRectangle(width / 2, height / 2);
            PolygonShape rectangleShape = new PolygonShape(rectangleVertices, density);
            newBody.CreateFixture(rectangleShape, userData);
    
            return newBody;
        }
    

    Instead, it creates a set of vertices that it assigns to the shape of the body (in this case a rectangle), however, it doesn’t appear from a cursory glance that there is a way to get at these vertices.

    So long answer short, there isn’t a direct method that I can find that will give you the straight float value of the height or width of your rectangle. You might be able to get at the vertices in some way and calculate it back out, but this would require you taking the Body and parsing through its fixture list and figuring out which one is your rectangle.

    At the end of the day, if you need to get directly at your Height and Width, I would recommend just creating a custom class and storing the body together with the float values, and using getters/setters. It’s likely to be a less expensive operation than looping through every fixture on your objects and trying to determine which is your rectangle and then calculating it back out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded the folder containing the Farseer Physics engine. and I have a
I am using Farseer Physics Engine to build a Monster Dash like game targeted
I was trying to get farseer physics engine to work. Everything compiles fine except
Anybody did compile Farseer Physics Engine 3.0 with XNA 4 ?
I'm writing a physics-based game which has planets with gravity acting upon various objects
I am new to the Farseer library and I am attempting to make a
I just started using the Farseer engine and so far it's been pretty easy
What's the best way to represent generated 2D terrain in Box2D/Farseer? The terrain consists
Ok, so I ended up writing my own game engine based on top of
I need to know how I can check in Farseer Physics if a player/user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.