Bouncy things in Defold(SOLVED)

Hello guys,
Just dropped in to ask how do we create things that bounce off walls, like breakout games, or bouncing bullets. I could understand the maths part, but don’t get how to convert it to code?

How much have you learned about vectors? Once you have vector based movement, doing vector reflections off surfaces is really easy.

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/ try reading through these first 1-4

3 Likes

Well, the most simple way to have objects that bounce is to use the built-in physics and set the restitution on the Collision Object component to whatever you want (up to 1).

If you want perfectly uniform, perpetual bouncing like a breakout game, it’s a different story. Last time I tried this it was definitely non-trivial. Maybe I was being stupid and overcomplicating it, but I believe you need to do your own Continuous Collision Detection, tracing the shape of your “ball” along its path each frame. This is because, especially at a measly 60 FPS, the exact time of the collision will always be in-between frames. If you don’t account for that, the “ball” will bounce along a slightly different path each time, and that error will get larger and larger over time.

You can probably still use the built-in physics for collision detection (with kinematic objects), and only do the math to get the exact bounce time when you get a hit. If your ball is moving fast enough to pass through things in one frame you can add a rough raycast check as well.

6 Likes

OOF :sweat: Solved it anyhow.
BTW @pkeod the document was very informative. I liked the knowledge and the presentation in a very crisp way

2 Likes