Bouncing and arcs
The math of things that fly: it works out the throw that lands exactly on a target, follows the arc and bounces off walls and floors. A ball bounces the same at any frame rate.
When you need it
For grenades, arrows, cannons, thrown items, an enemy that lobs at you, an aiming line, a basketball, or any bouncing ball.
Say this to your AI
Use the arcs from Spielerando so my enemy's grenade lands exactly where the player stands, and show an aiming line for my own throws.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
Settings
- gravity (980): The pull of gravity on a 2D screen, in pixels per second squared. In a 3D world in metres, use 9.81.
- bounciness (0.6): How much speed survives a bounce. 1 keeps it all, 0 stops dead.
- friction (0.1): How much sideways speed a bounce takes away.
- restSpeed (20): Below this speed a bouncing ball stops instead of jittering on the floor.
Your AI gets the code
The finished code and math come through the Spielerando connection, so your AI can use them right away. Connect your AI
Common questions
how do i make a projectile hit a target
Decide how long the flight should take, or how fast the throw is, and work backwards to the speed it needs at the start. There is an exact answer, so no guessing or adjusting by hand.
why does my projectile miss the target by a bit
Moving it in small steps every frame drifts away from the true arc, and more so at low frame rates. Use the exact position for each moment instead, and it lands on the spot.
why does my ball bounce higher and lower on different computers
The floor is crossed between two frames, and that small error differs per frame rate. The recipe works out the moment of the bounce inside the frame, so the height stays right.