【Unity】【C#】《U3d人工智能编程精粹》学习心得--------AI角色的感知方式-视觉感知实现解读
https://blog.csdn.net/Terrell21/article/details/82628621
自己效果实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Solider : MonoBehaviour
{
public float viewDistance = 5;
public float viewAngle = 120;
public Transform PlayerTranform;
void Start()
{
PlayerTranform = GameObject.Find("Player").transform;
}
void Update()
{
if (Vector3.Distance(PlayerTranform.position, transform.position) <= viewDistance)
{
Vector3 playerDir = PlayerTranform.position - transform.position;
float angle = Vector3.Angle(playerDir, transform.forward);
if (angle <= viewAngle / 2)
{
Debug.Log("在视野范围内");
}
}
}
}