Flipper like Game, Ball stuck in wall

Hej,

I have a flipper like Game with balls moving in a level.

Sometimes even with a very slow motion they get stuck in the walls.

They are all set to isBullet.

Any ideas on where to start searching for fixes?

What are your basic settings for a slow moving physics level?

Thanks,

Phil

I don’t use physics at all. I have seen this on occasion though in other applications. 

It usually occurs because code like the following exists, somewhere - this sort of thing is very common in pong/breakout type game code.

x = x + deltaX if x \< 0 or x \> 1020 then deltaX = -deltaX end

where x is the position and deltaX the velocity.  The idea is that if you bounce off the wall, the dx (horizontal velocity component) is reversed. 

The problem occurs because the object gets too far ‘into’ the collision, or sometimes if it moves at the same time as the collision, so when this is reversed, it doesn’t quite get it back to the required range, so it keeps doing the deltaX = -deltaX every step.

The fact that it only happens at very slow speeds (e.g. |dx| is very low) suggests possibly rounding errors, which a floating point only language like lua may be prone to in very borderline cases - you get the problem that 15.99999999 ~= 16 , even though the print routine may display it as 16.

The way round it (oddly I have just coded something similar today) is to set deltaX according to x, not to assume that the reversal works. I did it slightly more robustly because the velocity component could be anything (and i’m using velocity and direction rather than x/y components anyway)

Hej PaulScottRobson,

thanks for your reply.

Sounds like an interesting approach.

But how would I rewrite the physics lib? Or implement another way?

Any suggestions?

Thanks,

Phil

Honestly, I don’t know. I don’t use physics at all. It would be worth initially maybe printing out the physical position of the ball that appears to be ‘stuck’ - it may actually not be stuck, but be oscillating between two very close positions. Manually handle the collision maybe ?

I don’t use physics at all. I have seen this on occasion though in other applications. 

It usually occurs because code like the following exists, somewhere - this sort of thing is very common in pong/breakout type game code.

x = x + deltaX if x \< 0 or x \> 1020 then deltaX = -deltaX end

where x is the position and deltaX the velocity.  The idea is that if you bounce off the wall, the dx (horizontal velocity component) is reversed. 

The problem occurs because the object gets too far ‘into’ the collision, or sometimes if it moves at the same time as the collision, so when this is reversed, it doesn’t quite get it back to the required range, so it keeps doing the deltaX = -deltaX every step.

The fact that it only happens at very slow speeds (e.g. |dx| is very low) suggests possibly rounding errors, which a floating point only language like lua may be prone to in very borderline cases - you get the problem that 15.99999999 ~= 16 , even though the print routine may display it as 16.

The way round it (oddly I have just coded something similar today) is to set deltaX according to x, not to assume that the reversal works. I did it slightly more robustly because the velocity component could be anything (and i’m using velocity and direction rather than x/y components anyway)

Hej PaulScottRobson,

thanks for your reply.

Sounds like an interesting approach.

But how would I rewrite the physics lib? Or implement another way?

Any suggestions?

Thanks,

Phil

Honestly, I don’t know. I don’t use physics at all. It would be worth initially maybe printing out the physical position of the ball that appears to be ‘stuck’ - it may actually not be stuck, but be oscillating between two very close positions. Manually handle the collision maybe ?