Hi guys,
I'm still really not sure about how to implement jumping and gravity:
float3 position(0,0,0;
float3 velocity(0,0,0);
// this sums the forces
float3 sumForces()
{
float gravity=-4.0f;
return float3(0,gravity,0);
}
// this gets called every frame
void update(float dt)
{
// mass = 1 so acceleration = forces
float3 acceleration=sumForces();
position += velocity*dt;
velocity += acceleration*dt;
}
// this gets called when controller input changed
void onInput()
{
if(button_pressed){
// add jump but to what ?
forces.y=10.0f;
}
}
What do I do when the button is pressed for a jump ? I think I should add a positive y-value to the forces but where ? It has to go away after a second or two.
And my velocity y-value will continually decrease because of gravity so I have to clamp that to a lower limit, but what should that be ? Shouldn't my guy go faster and faster the deeper he falls ?
Thanks.