My main character is a ball that bounces forever at the same force. But I having difficulties finding the right way of bouncing at the same height as the game is increasing speed. Basically, here's my formula.
by the way, I'm using C++ and SDL2 so the Y axis is POSITIVE going down and NEGATIVE going up:
every frame, I'm adding the Yvelocity to the ball. Then I add the gravity to the velocity for gravity effect:
ballY += Yvelocity
Yvelocity += gravity
if(Yvelocity >= maxVelocity)
{
Yvelocity = maxVelocity
}
Then whenever I hit the ground, I do this to bounce the ball
Yvelocity = bounceForce; // -10 for example
Everything works great. But I want to make the game faster and faster. So every specific time I do this:
bounceForce += bounceForce * multiplier;
gravity += gravity * multiplier;
maxVelocity += gravity * multiplier;
...
//increase other object's speed too
The game speed is indeed getting faster but the bounce of the ball is also getting higher.
It looks like I have to increase the gravity more than bounceForce. So I tried doing this:
bounceForce += bounceForce * multiplier;
gravity += gravity * (multiplier * 1.5f); /////// <-------------------------
maxVelocity += gravity * multiplier;
...
//increase other object's speed too
That works fine at the beginning. But will likely do the same problem as the time goes by(bounces higher).
I think the more the Yvelocity is increasing, the more the gravity's multiplier has to increase too. Because the ball is getting lighter every increase of speed.
But I really can't find the right formula for that, of how I can make the ball bounce faster and faster but at the same height. Because it's not ideal for my game to increase speed then the ball is in constant speed. Sorry I'm a newbie in game programming. Thanks in advance.