erratic jumping

Started by
11 comments, last by Neen10do 20 years, 11 months ago
What fps are you getting, if the time difference is very low, it could mean DeltaTime is 0 almost and cause problems. If that is the case, then slow down your loop, using Sleep(1) or something. Just don''t forget to remove it later

Also don''t use s = ut + 0.5at^2, that doesn''t work for deltaTime. Your original code without a doubt is wrong, but with the time correction for the position being moved by the velocity, it should be ok.

Finally I can''t see what is happening with that ivvelocity. Is that supposed the be the velocity a frame ago, or the initial velocity. Either way I don''t think it''s needed.
Advertisement
"You fight like a cow..."....... I love MI.

-

If it was up to me, I would have gravity constantly being applied to the object. When the object jumps, I would apply the vector of the jump to the object (if the object is on the ground of course) and that is all. That way, the object would go up and then slowing come back down due to gravity. Since the vector's magnitude of the jump would be a constant (usually unless you wanted the player to jump at different heights (maybe based on their "jumping skill ability")) they would always jump the same height.

[EDIT] Please note that I haven't done a platformer yet.

- Rob Loach
Current Project: Go Through Object-Oriented Programming in C++ by Robert Lafore

"Do or do not. There is no try."
- Yoda


[edited by - Rob Loach on May 6, 2003 12:15:37 PM]
Rob Loach [Website] [Projects] [Contact]
quote:Original post by Neen10do
here is my code under Kyo''s suggestion:

//APPLIES PHYSICS//////////////
void cPhysics::ApplyPhysics(float &Xpos, float &Ypos, DWORD TimeDelta)
{

//if jumping
if(jumping)
{
//Moves object
Ypos = Ypos * TimeDelta + (float).5 * GRAVITY * (TimeDelta * TimeDelta);

//Terminal velocity
if(vVelocity > -120)
{
vVelocity = -120;
}
}
}
///////////////////////////////

the only problem with this is it has no velocity in it!! i dont know what s = ut + 1/2*a*t^2 is but i implemented the other one you gave me and it just sticks the dude on the cealing forever.

is there anyone in the world who has gotten this to work!?!?! some sample code, your game, whatever it takes!! this should not be that hard!!!!


----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!


Sorry I wasn''t thinking u isn''t yPos it''s the initial velocity. These equations come from newton''s laws:

a = [0, 9.8]

differentiate to get velocity

v = [u1, u2 + 9.8t]

differentiate to get displacement

s = [u1t + c1, u2t + 0.5*9.8*t^2 + c2]


That''s how I implemented my jump physics. u1 is your initial x velocity, u2 is your initial y velocity. These equations take 0,0 to be the bottom left corner though so you might have to modify the signs if your 0,0 is top left. c2 is your initial height.

You can use velocity equation to check when he''s falling back down , if velocity is negative he''s falling back down and you can do check for collisions downwards, if velocity is positive he''s moving updwards and you can check to see if he hit a ceiling.

you can make him jump faster and higher by modifying his initial velocity u.


This topic is closed to new replies.

Advertisement