1.根据玩家朝向判断预走位
2.发射目标点计算
3.设置发射朝向
(玩家预位置 = 玩家朝向归一化+玩家位置)
Vector3 f = Vector3.Normalize(playerTransform.forward);// normalized(playerTransform.forward); //playerTransform.forward.
int speed = playerContoller.IsStop == true ? 0 :2;
Quaternion newRotation = Quaternion.LookRotation(playerTransform.position+f*speed - transform.position);
turret.rotation = Quaternion.Slerp(turret.rotation, newRotation, Time.deltaTime * 10f);
完整NPC代码
//HM=====时间:
//设计内容:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTank : FSM {
public enum FSMStates
{
Patrol,
Chase,
Attack,
Dead
}
// Use this for initialization
[SerializeField] private FSMStates currentState = FSMStates.Patrol;