Graphic trailing Physics Body

Dec 2, 2009 at 2:58 AM

 

Hello, my game is doing some weird stuff now after I implemented my new class. I needed control of the head for the analog stick so I had to separate it into two separate textures. From there I gave a general position with a Vector2 that is assigned the world position determined by my squareBody. Once I have that, I just offset the characters textures to make it look normal. The thing is, the graphic trails behing the Physics Body. I don't understand it at all really. Maybe I'm just not setting the position very efficiently? Anyways here is what it looks like:

 

And the most obvious is here:

 

Any help would be great to this problem.

 

 

        public void Update(Vector2 physicsPosition, float rotation)
        {
            position = physicsPosition;
            head.Position = new Vector2(headPosition.X + (float)Math.Cos(rotation), headPosition.Y + (float)Math.Sin(rotation)) + physicsPosition;
            body.Position = new Vector2(bodyPosition.X + (float)Math.Cos(rotation), bodyPosition.Y + (float)Math.Sin(rotation)) + physicsPosition;

            head.Rotation = rotation;
            body.Rotation = rotation;
        }

 

 

This is how it looks right now. head and body are special classes that hold all of the parameters for the spriteBatch. physicsPosition is the position the geom is currently at (and my Math.Cos and other stuff may be wrong but I don't know for sure since I have no angles at all yet in my code). position is saved for the public property Position and allows setting and retrieving of what it stores.

Any help would be great, thanks!

 

Coordinator
Dec 2, 2009 at 3:09 PM

You need to get the timing of your position setting straight. It seems like you are updating the texture with the position of the geometry before it updated the physics simulator. This has happened a few times before by other users :) Make sure that you update the physics engine, save the positions and then draw using that position.

The physics simulator view (debug view) always draw the correct position since it accesses the properties on the geometries directly. If the debug view draws fine, you have something wrong with your drawing code.

Dec 2, 2009 at 3:45 PM

Ahh ok I get you. Thanks :)