Unity3D 人工智能(三) 感知系统

视觉可以分文两张 

第一种是判断距离  上一节已经讲过了

Unity3D 人工智能(三) 感知系统

这节课讲一下第二种  根据前方角度来判断

 

Unity3D 人工智能(三) 感知系统

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Soldier : 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("在视野范围内");
            }

        }

	}
}

 

相关文章:

  • 2021-07-15
  • 2021-09-23
  • 2021-05-25
  • 2021-07-30
  • 2022-01-21
  • 2021-12-29
  • 2021-12-03
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2022-01-02
  • 2021-05-13
  • 2021-03-28
  • 2021-08-09
  • 2021-12-18
  • 2021-09-23
相关资源
相似解决方案