Bouncing ball isssue
Posted
by
user
on Game Development
See other posts from Game Development
or by user
Published on 2013-10-20T06:54:51Z
Indexed on
2013/10/20
10:19 UTC
Read the original article
Hit count: 252
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();
}
© Game Development or respective owner