Answer the question
In order to leave comments, you need to log in
How to make a smooth turn to a point?
I make a movement on checkpoints
public class Unit : MonoBehaviour{
public Vector3 CheckPoint;
public int NumCheckPoint = 0;
public Dictionary<int, Vector3> CheckPointsMove = new Dictionary<int, Vector3>();
private float speed = 2f;
private GameObject head;
void Start(){
head = gameObject.transform.Find("Head").gameObject;
CheckPointsMove[0] = new Vector3(2, 1, 2);
CheckPointsMove[1] = new Vector3(10, 1, 2);
CheckPointsMove[2] = new Vector3(10, 1, 13);
}
void Update(){
MoveEnemy();
}
void MoveEnemy(){
head.transform.LookAt(new Vector3(CheckPoint.x, 0, CheckPoint.z));
if(CheckPoint==transform.position){
++NumCheckPoint;
foreach(KeyValuePair<int, Vector3> v in CheckPointsMove){
if(v.Key == NumCheckPoint){
CheckPoint = v.Value;
}
}
}
transform.position = Vector3.MoveTowards(transform.position, CheckPoint, speed*Time.deltaTime);
}
Answer the question
In order to leave comments, you need to log in
Why is he looking at the floor?
head.transform.LookAt(new Vector3(CheckPoint.x, 0, CheckPoint.z)
head.transform.LookAt(new Vector3(CheckPoint.x, head.transform.Position.y, CheckPoint.z)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question