Jumping system with FarseerEngine

Oct 9, 2010 at 3:23 PM
Edited Oct 9, 2010 at 4:20 PM

I am trying to make my character (3d model, but this doesnt matter) jumping in a 2d coordinate system (X and Y). I achieved this, but I have a problem. The first jump last TOT seconds, the second and the others keep decreasing in High (Y position). I debugged everything and discovered that the first jump, the Y Body.Position is decreased (every update cycle, so every frame) for only 0.13 , while for the second jump for 1.3 (more or less) and for the fouth (for example) 3.0 and so on.

So the jumps become less high after the first one. What can cause this problem? I was thinking that maybe the gravity applied by the Farseer Endine could be not constant (but It would be very odd)...otherwise, the force applied to the body change...(but I have debugged everything, and this forse remain constant on the Y  and of course on the X axis ). Moreover, even the Y position of the body is resetted to its original position, when the body touch the ground after a jump.

I think this is a issue of the engine itself, becouse very time the character performs a jump the parameters passed in are always the same.

Anyway this is the function: (durationJump si only used for testing the duration of each jump, infact the first one lasts 300 cycles more or less, the others much less).

 Then the velocity is added to the Position.Y value of the character and the Position 3d vector is applied to the world.translation matrix in order to move the 3d model on the screen.

Everytime the character touch the ground the Position.Y is restored to its original value (ground level) And everytime a jump ends, even the body position is restored to its original position. Maybe the problem is that I have created a body with a mass for rapresenting the 2d physics of my 3d model?

 

EDIT: I think I have found the problem, since gameTime.ElapsedGameTime take the amount of the elapsed game time since the last physics.Update its value is different for the jumps after ther first one becouse more time has passed since the last update of the physics object. But I have still the dubt, becouse maybe ElapsedGameTime is the amount of the elapsed game time since the last main Game1.Update ....and not physics.Update..

 

public

 

 void ApplyFarseerPhysics(GameTime

gameTime)

{

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

 

//elapsed += (float)gameTime.ElapsedGameTime.TotalSeconds; //* 1000;

durationJump++;

Velocity.X += body1.Position.X;

Velocity.X =

MathHelper

.Clamp(Velocity.X, 0.0f, MAXSPEED);

body1.ApplyForce(

new Vector2

(0000.0f, 5.0f));

Velocity.Y = body1.Position.Y;

 

//Velocity.Y = MathHelper.Clamp(Velocity.Y, -60.0f, 160.0f);

}