High velocity move and collision

Hi
I am newbie in defold. Now I create ping-pong like game and encountered a problem. Ball has high velocity and flies through barriers. I tried to move the ball nth times by speed * dt / n. But collision not update! What can I do with this??

This is a classic problem. Google for “bullet through paper”. I believe there’s a bullet flag on physics objects in Box2D but we do not expose it. One option would be to make the walls thicker. Another to change physics scale in game.project

I read smth about collision detect. Interesting, but I can’t write this bkz I can’t force update collision(( (for example, continues collision detect need update on each small step) (all right??) I see what some engines support CCD and can help with “bullet through paper". What about Defold??
I Change physics scale. Got better, but I don’t understand, what is it?? I didn’t find smth about it

There is a short description of the physics scale setting here: https://www.defold.com/manuals/project-settings/#_physics

Defold’s physics features are relatively limited. It uses Box2D, but a lot of Box2D’s features (like CCD) are not exposed, so you can’t use them. If you want a Pong or Breakout game with perfect bounces, that’s basically impossible to do with a physics engine anyway. You will need to make your own solution. You can use ray casts to do your own CCD. Cast a ray (or multiple rays) ahead of your ball to the point where it will be next frame (current_pos + velocity * dt) to see if it will hit something. If there is a collision, you can use the hit position and normal to calculate the ball’s position after the bounce. The ball should move forward until the contact point, reflect it’s velocity around the contact normal, and keep moving until it has traveled the full distance (speed * dt).

2 Likes