Hello,
i have created this script but this don’t rotate the object to the walking point.
whats wrong?
using UnityEngine;
using System.Collections;
public class PathFollower : MonoBehaviour {
public Transform[] path;
public float speed = 5.0f;
public float reachDist = 1.0f;
public int currentPoint = 0;
void Start(){
}
void Update(){
float dist = Vector3.Distance (path [currentPoint].position, transform.position);
transform.position = Vector3.MoveTowards (transform.position, path[currentPoint].position, Time.deltaTime*speed);
Vector3 newrot = Vector3.RotateTowards (transform.position, path[currentPoint].position, Time.deltaTime*speed, 1.0f);
transform.rotation = Quaternion.LookRotation(newrot);
GetComponent<Animation>().Play("WalkForward");
if (dist <= reachDist) {
currentPoint++;
}
if (currentPoint >= path.Length){
currentPoint = 0;
}
}
}