I am using this script for AI movement but the object instantly turns to the direction of the next waypoint then when it reaches the current waypoint and as it is a tailship it doesn’t look right. I would also like to wait at the last waypoint before doing the loop again.
Im not using the last part of the script as its not needed.
thanks
using System.Collections.Generic;
using UnityEngine;
public class AIwayPiontcontroller : MonoBehaviour
{
public GameObject[] waypoints;
int current = 0;
public float rotSpeed = 2.0f;
public float speed;
float WPradius = 1;
// Update is called once per frame
void Update()
{
if (Vector3.Distance(waypoints[current].transform.position, transform.position) < WPradius)
{
current++;
if (current >= waypoints.Length)
{
current = 0;
}
}
gameObject.transform.LookAt(waypoints[current].transform.position);
transform.position = Vector3.MoveTowards(transform.position, waypoints[current].transform.position, Time.deltaTime * speed);
}
public void Move()
{
//gameObject.transform.LookAt(waypoints[current].transform.position);
//gameObject.transform.position += gameObject.transform.forward * speed * Time.deltaTime;
}
}