Im porting my box2d project from Java to c# (XNA). But i've got some problems with the gravity and other forces.
The bodies are falling with a linear velocity (no acceleration), and I dont understand why.
I made a simple code just to test the effect of these forces.
I just created a new Windows Game Project in the "Visual C# 2008 Express Edition", then I imported the Box2D.XNA libraries and created the function createWorld().
I call the createWorld() inside the Initialize() function and call the world.Step() inside the Update() function.
And finaly, inside the Draw() function I draw a sprite (using the spriteBatch.Draw) passing the body.GetPosition() in the position parameter.
It's a simple approach and I dont understand why it doesn't work.
Please help me.
This is the link to the complete project: http://rapidshare.com/files/338343452/WindowsGame9.rar.html
Here follows the main part of the code:
protected override void Update(GameTime gameTime)
world.Step(1/60, 8, 3);
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
protected void createWorld()
world = new World(new Vector2(0, 100), false);
PolygonShape polygonShape = new PolygonShape();
FixtureDef polygonDef = new FixtureDef();
polygonDef.shape = polygonShape;
polygonDef.density = 5;
polygonDef.restitution = 0.5f;
polygonDef.friction = 0.5f;
polygonDef.isSensor = false;
BodyDef bodyDef = new BodyDef();
bodyDef.position.X = 400;
bodyDef.position.Y = 0;
bodyDef.angle = 0;
bodyDef.fixedRotation = false;
bodyDef.type = BodyType.Dynamic;
body = world.CreateBody(bodyDef);
PS: It seems the top speed reached through acceleration in this manner is equivalent to twice the value 60, as i used in world.Step(1/60, 8, 3);
If I leave it as 60, for instance, the maximum speed is 120, if I change it to 80, the maximum speed becomes 160.