i finally got my jumping for my dude to work... kinda sorta. when the player jumps, it sets the velocity at a constant rate, ie 80. but each time the player jumps, it goes to different heights. considering the velocity always starts the same, and there are no external factors, why wouldn''t it jump the same every time? here is some code
input function
void cMainGame::CheckInput()
{
//BUTTON PRESSES///////////
static bool Z;
///////////////////////////
//this just keeps the player from going through the floor, for now. primiative collision.
if(Player.mySprite.myY >= 396)
{
Player.myPhysics.vVelocity = 0;
Player.mySprite.myY = 396;
Player.myPhysics.jumping = false;
}
switch(GameMode)
{
//The Game is Running
case MainGame:
//Jump
if(dk.KeyPressed(DIK_Z))
{
if(Z == false)
if(Player.myPhysics.jumping == false)
{
Player.Jump(80);
}
Z = true;
}
else
{
Z = false;
}
break;
default: break;
};
here is the jump function
//Makes the object jump based on physics
void cObject::Jump(int velocity)
{
myPhysics.jumping = true;
myPhysics.vVelocity = velocity;
}
//////////////////////////////////////////
and here is the physics function that is applied to the object every frame. TimeDelta is the difference between frames, in milliseconds.
//APPLIES PHYSICS//////////////
void cPhysics::ApplyPhysics(float &Xpos, float &Ypos, DWORD TimeDelta)
{
//if jumping
if(jumping)
{
//Terminal velocity
if(vVelocity > -100)
{
//Applies Gravity
vVelocity = vVelocity + (int)GRAVITY * TimeDelta;
}
//Moves object
Ypos = Ypos - (vVelocity / 10);
}
}
///////////////////////////////
can you guys find any reason my jumping would be erratic?
----------------------
i code therefore i am.
Aero DX - Coming to a bored Monitor near you!
----------------------i code therefore i am.Aero DX - Coming to a bored Monitor near you!