Rendering texture at body position offsets at high speeds

Topics: Developer Forum, User Forum
Jul 29, 2009 at 10:31 AM


We seem to have a little problem with bodies positions at high speeds. They seem to be more offset the higher the speed. To render our images at the corresponding body positions we just do  the following at the update stage

  m_playerEater.Position = new Vector3(rectBody.Position, 0.0f);

And the following at the render stage we render our image at the position set in update, everything as you normally do. But the position we get from body seems to be more offset the higher the speed, and you can clearly see the image swaying inside the rect of the Geom. Any ideas if this is something thats expected in Farseer?

Heres a link to a clip showing the problem:


Jul 29, 2009 at 3:51 PM

I had this same problem when I was first implementing Farseer.  I was updating the sprites position BEFORE the PhysicsSimulator update.  Either do it after the PhysicsSimulator update, or at the beginning of the Draw command.

Jul 29, 2009 at 4:20 PM
Edited Jul 29, 2009 at 4:54 PM

I've tried to update differently... currently I'm updating the physics simulator first allowing it to simulate then I update my game logic which retrieves the current position of the Farseer bodies and sets our quads (not using sprites) at those positions... as you normally would do.

Didn't solve my problem... very strange this.

Jul 29, 2009 at 6:07 PM

I resolved it by giving each object an Update() method and an AfterUpdate() method.  The problem you have is that the sprite position update is happening at the same time you apply a force to it.  The force isn't actually applied, however, until the PhysicsSimulator update.  This causes the Sprites position to be updated at the old position, then the body and geom are moved, then you draw. 

Here is an example of my Update code:

physicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);

Then, my player1 object has these methods:

public void Update(GameTime gameTime)
//Player input

public void AfterUpdate(GameTime gameTime)
Sprite.Position = PhysicsBody.Position;
Sprite.Rotation = PhysicsBody.Rotation;
Alternatively, you can add the Sprite position and rotation update to the beginning of your objects Draw method (instead of having an afterupdate method).

Jul 30, 2009 at 7:49 AM
Edited Jul 30, 2009 at 7:50 AM

Sorry to say that it didn't help. Tried to update our objects positions from the physics bodies just before draw.

I'm starting to wonder if theres something else wrong with our code. Maybe in our matrixstack or when we convert 3D coordinates to screen coordinates. But even that doesn't really add up. The offset increases with the speed of the object and decreases again when the objects slows down. Our debug data is rendered in the same manner as our objects and in the same order. Any other ideas? Any params that we haven't set?

Jul 30, 2009 at 8:00 AM

Well, the debug view works since it follows the geometry. It is not physics engine related, so it must be in your drawing code. I've observed this before and it was due to floating point errors. problem was that you put a lot of speed on the geometry and you still use camera positions related to the original position of the camera and not a relative position to the object you track.

Floating points are not 100% accurate and their errors can build up over time and they will build up faster if you increase their value faster. There are some info about it here and here.

Jul 30, 2009 at 8:11 AM
Edited Jul 30, 2009 at 8:11 AM


We just found out that our objects seem (although it's hard to test) to collide as they should, they just don't line up with the debug view of the simulator. So I definitely agree with you that this is something caused by no one else than our selves. We are grateful for all your input and we'll keep on testing this to find out where the error lies.