Bouncing ball isssue
- by user
I am currently working on the 2D Bouncing ball physics that bounces the ball up and down. The physics behaviour works fine but at the end the velocity keep +3 then 0 non-stop even the ball has stopped bouncing. How should I modify the code to fix this issue?
ballPos = D3DXVECTOR2( 50, 100 );
velocity = 0;
accelaration = 3.0f;
isBallUp = false;
void GameClass::Update()
{
velocity += accelaration;
ballPos.y += velocity;
if ( ballPos.y >= 590 )
isBallUp = true;
else
isBallUp = false;
if ( isBallUp )
{
ballPos.y = 590;
velocity *= -1;
}
// Graphics Rendering
m_Graphics.BeginFrame();
ComposeFrame();
m_Graphics.EndFrame();
}