Navigation Header

Tutorial 6: Detecting and resolving collisions

We work on top of Tutorial 5 and implement collision detection, so our agents don't overlap. In process we will get more familiar with vectors and what we can use them for.



Links

Starter code (tutorial 5 code)

Final code after tutorial

Supplementary/Optional links Additional information

There are other approaches to collision resolution: for example if your agent had velocities, you could apply small pushes to all agents that overlap by adding components to their velocity that makes them go apart. I see the approach we covered in this tutorial to be superior, however.

Note also that we are doing all collision checks twice for every pair of agents. For example, we check agent 3 does not overlap with agent 7, and then later check (again) that agent 7 does not overlap agent 3. It's not a big deal and can be fixed easily.

FAQ Code