Ariel and I have been hard at work trying to finish the designs of all our game elements. It’s part of our push to get a level built from every area in our game. One of the newest game elements is a police drone that searches for Ki. I wanted to have a visual for where the drone was searching. Something like this:



One approach is to do something called “raycasts” from where the drone is towards where it’s looking. These casts outwards might bump into something and that will tell you if the the drone can see that thing or not. But, in order for you to visualize where the drone can see, you need to send a LOT of raycasts.


Screenshot showing raycasts from interactive demo at


And even then, when you make the visualization, you’ll get corners chopped off because of the limited resolution of the raycasts:


Screenshot showing shape created by raycasts from
Circles pointing out where corners get chopped off.


So I looked for a better way. Luckily, there are amazing indie developers out there willing to share their struggles and accomplishments. We found a really fun blog post by the makers of “Nothing to Hide”:

I HIGHLY recommend checking out that post – it has a set of AMAZING demos that explain this problem and his solution.

The trick to get a good, cheap visualization is to know what terrain is in your scene and to find the corners of each terrain object. You can cast directly to the corners instead of “blindly” casting everywhere. There’s a bit more to it than that, but you can check out his original post for more details.

Here’s another picture taken from the demo on his post:



And the visualization created by it is just awesome.


For the police drone, I had to adapt the strategy a bit – the raycasts were coming from a face of the drone instead of a point, and there was an angle limit to the casting that I wanted. But overall, it worked really well. I could even move it around and it updated smoothly:



Here is the debugger showing all my raycasts (in white) and you can see the mesh in orange outline at the beginning



After creating the mesh and applying the same points of the mesh to a player-seeking collider, I was finally able to activate the drone when the player entered the area.


Author Kent Willis
Categories Uncategorized
Views 2598


No Comments

Leave a Reply