This project has moved and is read-only. For the latest updates, please go here.

Position of my ground body wrong

Topics: Developer Forum, User Forum
Mar 30, 2013 at 12:55 PM
Edited Mar 30, 2013 at 5:57 PM

I want to have a block which falls down and stops on the ground, but the position of the ground seems to be wrong. If the size of the block is 48px it falls down 21.00039px to much and when I move it to the right the ground ends after the red line in this picture:

And when I move it to the left out of the window it doesn't fall down when i don't move it to much to the left.

Here's the code (screen height is 544px and width is 960px):
   World world = new World(new Microsoft.Xna.Framework.Vector2(0,9.82));
   Body rectangleBody = BodyFactory.CreateRectangle(world,48f/100f,48f/100f,1f,
   new Microsoft.Xna.Framework.Vector2(0,0));
   rectangleBody.BodyType = BodyType.Dynamic;
   Body groundBody = BodyFactory.CreateRectangle(world,960f/100f,1f/100f,1f,
   new Microsoft.Xna.Framework.Vector2(0,543f/100f));           
   groundBody.IsStatic = true;

   sprite.Schedule( (dt) => {
   sprite.Position = new Vector2(rectangleBody.Position.X * 100f, 544f - rectangleBody.Position.Y * 100f - 48f);

I'm using PlaystationMobileSDK and actually farseer works very good.
Any advice how I can fix it?
Thanks in advance!

Edit: It seems that if both bodies have the same size the collision is right. So there's something wrong with the collision, not with the position, if the bodies don't have the same size. Maybe farseer has some problems with the collision on PSM SDK? Any advice?
Apr 8, 2013 at 3:52 PM
Generally speaking you do not want a 1 to 1 correlation between your physics simulation and your rendering. This is a common problem. Farseer units are in meters. The way you've setup your simulation you're treating each pixel as 1 meter. That's probably not what you want. A better approach is to decide on the size of the things you're trying to model in the real world (for example: if you were modeling a tall man you might make him 2 meters tall by 0.5 meters wide), and then scale when you draw/render.

At any rate, your problem is with your drawing. The physics simulation and the drawing are completely separate. If it doesn't look like the bodies are colliding at the right place, it's because you're not drawing it correctly, not because there's something wrong with the physics.

Hopefully that makes sense and is helpful,
Jun 3, 2013 at 9:14 PM
Thanks, but as you can see in the code i posted i already did it. 100 pixel are 1 meter...