Unity 两种敌人AI导航方式

public class EnemyMove : MonoBehaviour {

    private Transform player;
    private Rigidbody rigid;
    private NavMeshAgent agent;

    private void Awake()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;
        rigid = this.GetComponent<Rigidbody>();
        agent = this.GetComponent<NavMeshAgent>();
    }
    // Use this for initialization
    void Start () {
        


    }
    
    // Update is called once per frame
    void Update () {

     //通过导航网格导航

        agent.SetDestination(player.position);
    }
    private void FixedUpdate()
    {
        //刚体导航
        Vector3 direction = player.position - transform.position; //确定目标方向
        Vector3 deltaVelocity = direction - rigid.velocity;
        rigid.AddForce(deltaVelocity, ForceMode.Force); 

    }

没有更多推荐了,返回首页