Back to Physics in Simulations
AdvancedAdults

Collision Response

Once you detect a collision, what do you do? This is **collision response**. The goal is to make objects react realistically.

For simple AABB (Axis-Aligned Bounding Box) collisions, the simplest response is to stop the objects from overlapping.
1. **Find the Overlap:** Calculate how much the two boxes are overlapping on the X and Y axes.
2. **Resolve the Overlap:** Move one or both of the objects so they are just touching. Usually, you move them along the axis with the *smallest* overlap. This is called the Minimum Translation Vector (MTV).
3. **Update Velocity:** For a realistic bounce, you need to change the object's velocity. For a simple bounce off a wall, you reverse the velocity component for that axis.
- Hitting a vertical wall: velocity.x = -velocity.x
- Hitting a horizontal surface: velocity.y = -velocity.y

For more complex physics (like two balls hitting each other), you need to account for their mass and angle of impact using momentum conservation formulas. This can get very complex, but the basic principle of resolving the overlap and then adjusting velocities is the same.