public GameObject Hero;
public GameObject Monster;
private float length = 10;
private float angle = 120;
void isLookHero() {
// 求二者间的距离
var heroToMonsterLength = Vector3.Distance(Hero.transform.position, Monster.transform.position);
// 角色和怪物正前方夹角
var heroToMonsterAngle = Vector3.Angle(Monster.transform.forward, (Hero.transform.position - Monster.transform.position).normalized);
if (heroToMonsterLength < length && heroToMonsterAngle < angle / 2) {
Debug.Log("发现玩家");
}
}
通过怪物和玩家之间的距离和怪物视线夹角可以判断玩家是否在怪物视野中。
标签:Hero,Monster,Vector3,transform,怪物,position,向量 From: https://www.cnblogs.com/wuzhongke/p/16836314.html