Learn Vector Mathematics, kids

I have been messing around with the Unity Engine recently as a part of my most recent and mysterious side project, and boy am I glad that I paid attention in math class.

Today I set about modifying a movement function for an entity that just loved to run into walls. Using some simple vector mathematics I was able to do it very simply. In the diagram you can see a round entity. The straightest path to the entity's target is bordered by the red lines. Unfortunately there is an obstacle to the entity's right. The blue lines show points of possible contact. The center blue line goes straight toward the target from the entity's center. The other two blue lines are drawn from the entity's center to the point where one of the red lines hits something. In the diagram we can see one of the blue lines crossing a red line. This point represents our nearest obstacle. The blue line that hits this obstacle is reflected over the vector pointing straight toward the entity's target, resulting in the green line. This green line is the movement direction for the entity. It's a simple avoidance function, but it appears to be robust enough for my purposes.

Without a good foundation in Math I am sure I would have been lost tackling this problem. So remember, kids: always pay attention in Math class

Previous
Previous

Announcing: Cubes!

Next
Next

Learning 3D Modeling