如何检查一个游戏对象是否可以看到另一个? [英] How can I check if one game object can see another?

查看:86
本文介绍了如何检查一个游戏对象是否可以看到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个物体,该物体面向特定方向,例如(45度)视野和一个极限视野范围.我已经完成了所有的初始检查(四叉树节点和距离),但是现在我需要检查某个特定对象是否在该视锥内(在这种情况下,如果可以看到,则决定只跟随该对象).

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, and distance), but now I need to check if a particular object is within that view cone, (In this case to decide only to follow that object if we can see it).

除了为从Direction - (FieldOfView / 2)Direction + (FieldOfView / 2)的每个度数投射射线(目前我正在这样做,这很可怕)之外,进行此可见性检查的最佳方法是什么?

Apart from casting a ray for each degree from Direction - (FieldOfView / 2) to Direction + (FieldOfView / 2) (I am doing that at the moment and it is horrible), what is the best way to do this visibility check?

推荐答案

计算视图方向(理解为矢量)与以您为起点并以对象为终点的矢量之间的角度.如果它属于FieldOfView/2,则可以查看该对象.

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.

那个角度是:

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

这篇关于如何检查一个游戏对象是否可以看到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆