using UnityEngine;
using System.Collections;
public class enimiy : MonoBehaviour {
public Transform target;
public float moveSpeed =1;
private Transform thisT;
void Start () {
}
//游戏唤醒后赋值
void Awake(){
thisT = this.transform;
}
void Update () {
MoveToPoint (target.position);
}
private float rotateSpd =5f;
//Slerp慢慢的转向目标
void MoveToPoint(Vector3 point){
Quaternion wanteRot = Quaternion.LookRotation (point - thisT.position);
thisT.rotation = Quaternion.Slerp (thisT.rotation, wanteRot, rotateSpd * Time.deltaTime);
// normalized是把vector3变成一个大小为1的值
Vector3 dir = (point - thisT.position).normalized;
thisT.Translate (dir * moveSpeed * Time.deltaTime, Space.World);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
塔防TDTK 敌人移动到目标转向
原文:http://blog.csdn.net/haifeng619/article/details/47723045