Unity – How to make things see where they’re going

While developing a game, I wanted to enable the autonomous characters to see where they’re going – that is, to tell them what they’re about to stumble into, without using colliders. The answer was to cast a Ray, angled slightly downward, in front of the character, so it can see if it’s about to walk into a tree, or off a cliff, before it happens.

The image at the top of the post shows a dog character casting a Ray (yellow line) downward in front of him, through the floor. But the Ray intersects a tree and points the object out to him (red line). I do this like so: I hope that’s useful to someone – happy coding 🙂