Home
GGJ Archives 2009-2012

Seeing the enemy is key

jordi.fita

We finally managed to create a guard that is able to see the player. And by see I mean that is able to know whether the center of the player is inside its own field of vision.

Now, I must admit that I am not very good at math, and I know that this prevents me doing the "great tricks" we are used to see in great games. I'll improve, though.

But, doing some brainstorming we found a way of doing exactly that. Let's assume the guard has a FOV of 70º and can see four meters ahead. Then, two know if the player is within the FOV we just need to compute the dot product between the direction vector (the vector that is always ahead and has the yaw) and the vector between the player's position and the guard's origin. Then, we just can do: acos(dot(a, b)/(len(a) * len(b)). If the distance between the player and the guard is less then four meters and the angle is less than 35º (70º / 2), then the player is seen and lost.


Follow

All rights reserved 2012-2013, Global Game Jam