Jittering AI Movement.
Posted: Wed Dec 22, 2021 2:51 am
Hi Guys.
I'm a noob regarding C++ but well I like to do some programming here and then.
I was trying to make a simple PONG game with some AI oponent but the oponent moves are very jitter...
I've uploaded a small video screen capture: https://we.tl/t-a8Qv8CVytO where you can see the problems:
- AI Paddle doesn't stop...it keeps hitting the top/bottom border like it's remembering the last move...after ball is lost too.
- AI Paddle movement is kinda jumpy.
here's the code for the UPDATE function of CGamePaddle and CGameAI classes:
void CGamePaddle::Update(float dt)
{
if (m_bPushingUp)
{
SetVelocity(vector3df(0, 400, 0));
}
else if (m_bPushingDown)
{
SetVelocity(vector3df(0, -400, 0));
}
else
{
SetVelocity(vector3df(0, 0, 0));
}
IGameEntity::Update(dt);
Collisions(); //with border
}
void CGameAI::Update(float dt)
{
//m_pPaddle->Stop();
m_vIntersection = vector3df(0, 0, 0);
m_bTRavellingLeft = false;
CheckTravelling(); //assigns true or false for m_bTRavellingLeft and if ball has passed half the game width.
vector3df ballpos = m_pGameManager->GetBall()->getMeshNode()->getAbsolutePosition();
vector3df paddlepos = m_pPaddle->getMeshNode()->getAbsolutePosition();
if (m_bTRavellingLeft)
{
if (paddlepos.Y + PADDLE_HEIGHT / 2 < ballpos.Y || paddlepos.Y - PADDLE_HEIGHT / 2 < ballpos.Y)
{
m_pPaddle->PushUp();
}
if (paddlepos.Y + PADDLE_HEIGHT / 2 > ballpos.Y || paddlepos.Y - PADDLE_HEIGHT / 2 > ballpos.Y)
{
m_pPaddle->PushDown();
}
}
else
{
m_pPaddle->Stop();
}
}
I'm a noob regarding C++ but well I like to do some programming here and then.
I was trying to make a simple PONG game with some AI oponent but the oponent moves are very jitter...
I've uploaded a small video screen capture: https://we.tl/t-a8Qv8CVytO where you can see the problems:
- AI Paddle doesn't stop...it keeps hitting the top/bottom border like it's remembering the last move...after ball is lost too.
- AI Paddle movement is kinda jumpy.
here's the code for the UPDATE function of CGamePaddle and CGameAI classes:
void CGamePaddle::Update(float dt)
{
if (m_bPushingUp)
{
SetVelocity(vector3df(0, 400, 0));
}
else if (m_bPushingDown)
{
SetVelocity(vector3df(0, -400, 0));
}
else
{
SetVelocity(vector3df(0, 0, 0));
}
IGameEntity::Update(dt);
Collisions(); //with border
}
void CGameAI::Update(float dt)
{
//m_pPaddle->Stop();
m_vIntersection = vector3df(0, 0, 0);
m_bTRavellingLeft = false;
CheckTravelling(); //assigns true or false for m_bTRavellingLeft and if ball has passed half the game width.
vector3df ballpos = m_pGameManager->GetBall()->getMeshNode()->getAbsolutePosition();
vector3df paddlepos = m_pPaddle->getMeshNode()->getAbsolutePosition();
if (m_bTRavellingLeft)
{
if (paddlepos.Y + PADDLE_HEIGHT / 2 < ballpos.Y || paddlepos.Y - PADDLE_HEIGHT / 2 < ballpos.Y)
{
m_pPaddle->PushUp();
}
if (paddlepos.Y + PADDLE_HEIGHT / 2 > ballpos.Y || paddlepos.Y - PADDLE_HEIGHT / 2 > ballpos.Y)
{
m_pPaddle->PushDown();
}
}
else
{
m_pPaddle->Stop();
}
}