Hey guys,
so I wrote this script:
public float speed;
public int currentWayPoint;
public Transform[] Waypoints;
Transform targetWayPoint;
void Update ()
{
if (currentWayPoint < this.Waypoints.Length)
{
if (targetWayPoint == null)
targetWayPoint = Waypoints [currentWayPoint];
Walk ();
}
}
void Walk ()
{
transform.forward = Vector3.RotateTowards (transform.forward, targetWayPoint.position - transform.position, speed * Time.deltaTime, 0.0f);
transform.position = Vector3.MoveTowards (transform.forward, targetWayPoint.position, speed * Time.deltaTime);
if (transform.position == targetWayPoint.position)
{
currentWayPoint ++ ;
targetWayPoint = Waypoints [currentWayPoint];
}
}
The object should go from one waypoint to the other and so on. But as soon as I hit play the object teleports itself to the player gameobject and I don’t know why.