Subscribe to our subreddit to get all the updates from the team!
First off, here's a video that shows the unit vision in action :
So, what is the unit vision? It's a simple mechanism that notifies a unit when another unit enters its vision field. It also takes into account if the vision is blocked by entities.
This is how it is implemented step by step :
- A cone ghost control is attached to the unit's head
- All units intersecting with the cone's AABB fire events (AABB because of how Bullet Physics work)
- Cast a ray towards the visible unit and then adjust the angle so that it fits in the cone
- If the ray cast touches the supposedly visible unit, then it is truly visible
Using the debug view of Bullet Physics in the jMonkey Engine 3.1, we're able to see what the vision cone actually looks like.
And when inside the cone we can't see it because of culling. However, we can see the enemy's arm moving, which is a test I did for when a unit see another unit.
Behind a box, the enemy does not move its arm because he can't see me.
But when I leave my hiding spot, he can see me again.