setVelocity and avoiding a collision

I am re-creating pong

I want my ball to bounce of the walls which it does (result)

I have written an ai paddle for the player to play against

However at the moment the ai paddle hits the walls and bounces of them

Each time the step is called (every 20 milliseconds or so) on the box2d world I check the paddles position and velocity

My world is 500 high (with walls 2 meters high) so when the paddle is at 450 and is travelling downwards I set the velocity = 0

However my paddle always hits the wall!

I've added logging code and it appears my check is called too late - even though its called with every step!

Any ideas?
so. maybe your paddle is getting to 449, then stepping pushes it to 500?

Why not just make the restitution of the walls and paddle 0.0 and add restitution to your ball? That way the paddle will just hit the wall and stop dead whereas your ball will bounce off.

Of if you don't want to paddle to hit the wall at all, use a contact filter
snowcrash wrote:
so. maybe your paddle is getting to 449, then stepping pushes it to 500?

Why not just make the restitution of the walls and paddle 0.0 and add restitution to your ball? That way the paddle will just hit the wall and stop dead whereas your ball will bounce off.

Of if you don't want to paddle to hit the wall at all, use a contact filter

Hehe...isn't this thread almost two months old? I'm guessing the OP has solved his problem or moved on by now! (Could be wrong though, I suppose :)
Yeah.. I was just going through unanswered posts looking for easy ones 🙂

I hate it when your looking for a solution and find the perfect post only to discover it was never answered, so though it may benefit someone out there...

Original thread: https://box2d.org/forum/viewtopic.php?t=4652