Skip to content
Lesson 8 of 14

Step 1 of 5 · Reading · ~2 min

Read

Collision Response

Collision Response

When bodies collide, separate them and apply impulse for bounce.

Position correction: push apart along normal by penetration depth.

python

inv_mass = 1/mass for finite mass; 0 for static (immovable). The 0.8 factor (slop): slowly correct over multiple frames to avoid jitter.

Impulse: instantaneous change in velocity to simulate bounce.

python

This conserves momentum and produces realistic bouncing.

Friction:

  • Tangent direction: perpendicular to normal in plane of motion.
  • Tangential impulse: limited by Coulomb friction (μ * normal_impulse).
python

Produces sliding behavior.

Restitution (e):

  • 1.0: bouncy ball.
  • 0.5: rubber.
  • 0.0: clay (no bounce, sticks).

In real games: tuned per material.

Static vs dynamic bodies:

  • Static: inv_mass = 0, doesn't move (walls, floors).
  • Dynamic: full simulation.
  • Kinematic: scripted movement, no force-driven.

For our toy: handle 2D rigid bodies, support all three types.

Up nextConstraints (Joints)Collision Response

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…