I'm looking at how to implement a vision cone for my AI. Everything I look at talks about a forward vector, but in my situation, and I'm not that great with math, I have a vector but it doesn't give any orientation just the 3D point of where the entity is. The entity does have a separate rotation value. When people talk about forward vector are they talking about the rotation vector?

So if I just have a rotation vector and a location vector how can I make a vision cone in 3D from those values with say a variable degree of vision in both "left/right" and "up/down"?

I have some math functions available like ATan2()/Tan(). Not 100% sure how those play into this though.


You need a way to convert that rotation vector into either a Matrix or a Quaternion. Some math librarys have a built in method for doing that. If you choose a Matrix, then assuming you are in a Y-up world, the 3rd row or column (depending on if you are using DirectX or openGL) is a vector representing the direction your entity is looking (call it entityForward or something). This vector is probably already normalized but if not, then normalize it (divide it by it's own length).

If you choose a Quaternion then you must transform your world's forward vector by the quaternion and that will give you the same vector as the 3rd row/col that the matrix did.

Once you have that, you use it to measure the angular difference to any other object you want using the dot product.

Vector toOtherObject = otherObjectPosition - entityPosition;
if(Dot(entityForward, toOtherObject) > 0.707f)//.707 == 90 degrees field of view. 1 == 0 deg, 0 == 180 deg.
  //otherObject is in view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.