How can I check if one game object can see another?

前端 未结 3 1949
攒了一身酷
攒了一身酷 2021-02-15 00:24

I have an object, that is facing a particular direction with (for instance) a 45 degree field of view, and a limit view range. I have done all the initial checks (Quadtree node,

3条回答
  •  执笔经年
    2021-02-15 00:59

    Compute the angle between your view direction (understood as a vector) and the vector that starts at you and ends at the object. If it falls under FieldOfView/2, you can view the object.

    That angle is:

    arccos(scalarProduct(viewDirection, (object - you)) / (norm(viewDirection)*norm(object - you))).
    

提交回复
热议问题