Jittering AI Movement.

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
elektrikboy
Posts: 17
Joined: Wed Dec 22, 2021 2:30 am

Jittering AI Movement.

Post by elektrikboy »

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();
}
}
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Jittering AI Movement.

Post by CuteAlien »

When paddelPos.Y plus something is already smaller than ballpos then paddlepos.Y minus something will always also be smaller. So the part behind || can never result in something different.
So maybe check those checks again if they really do what you think they do.
My guess would be you only want to check for paddlepos.Y - PADDLE_HEIGHT / 2 < ballpos.Y (aka paddle is fully above the ball).

Same for the other check.

Also be a bit careful with getAbsolutePosition() - it is only updated with updateAbsolutePosition() which only happens once per frame unless you call it yourself. If your nodes don't have a hierarchy (parent-childs) it's easier to work with getPostion/setPosition. Otherwise call updateAbsolutePosition() before getAbsolutePosition() (at least when it changed). In case you wonder - it's some optimization (there are cases where it calculates matrices a lot otherwise).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
elektrikboy
Posts: 17
Joined: Wed Dec 22, 2021 2:30 am

Re: Jittering AI Movement.

Post by elektrikboy »

yes the getabsolute was giving some trouble for sure. I guess next step is making the AI a little dumber. thank you very much for yout awnser man
elektrikboy
Posts: 17
Joined: Wed Dec 22, 2021 2:30 am

Re: Jittering AI Movement.

Post by elektrikboy »

CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Jittering AI Movement.

Post by CuteAlien »

Nice! And I suppose the only way to win is not to play? ;-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
elektrikboy
Posts: 17
Joined: Wed Dec 22, 2021 2:30 am

Re: Jittering AI Movement.

Post by elektrikboy »

ahah you got that one right!!
hey sorry for the off topic - this is for another project im trying to implement...im trying to make some kind of abstract art here so i thought the only way would be to use some shaders...i want to make my renders look like they we're hand drawed...could you point me some literature on how could I achieve such thing???
thank you very much
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Jittering AI Movement.

Post by CuteAlien »

Yeah, this likely will need shaders. Irrlicht has a shader example for how to get them running. Beside that I don't know much about this specific problem. Maybe browse shadertoy.com a bit to get some ideas. If you have specific questions about shaders I might be able to help again. Could speculate a bit, but running out of time today (got to catch a train). Good luck.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
elektrikboy
Posts: 17
Joined: Wed Dec 22, 2021 2:30 am

Re: Jittering AI Movement.

Post by elektrikboy »

ok thank you very much for your time. i will read and get acquainted and when I have something more coesive we will talk again for sure.
happy holidays!!
Post Reply