Pointing towards Waypoint

i need help with my waypoint system! I didnt make this script and i dont know what to change.
right now the character goes towards the waypoint perfectly, but i need him to POINT towards the next waypoint. is there a way to do this? here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Waypoint : MonoBehaviour
{
public GameObject waypoints;
int current = 0;
float rotspeed;
public float speed;
float WPradius = 1;

void Update()
{

    if (Vector3.Distance(waypoints[current].transform.position, transform.position) < WPradius)
    {

        current++;
        if (current >= waypoints.Length)
        {

            current = 0;

        }
    }
    transform.position = Vector3.MoveTowards(transform.position, waypoints[current].transform.position, Time.deltaTime * speed);

}

}

2 Answers

2

And you’ve added to the waypoints array (public GameObject waypoints;) in the Unity editor additional points?

Add this line in your Update(), assuming your character’s forward direction is its local positive z axis.

transform.rotation = Quaternion.LookRotation(waypoints[current].transform.position - transform.position)