I am making a 2d tower defense game and I made a mistake with Quaternion Look Rotation

I am a beginner and was using tutorials on yt to make waypoints. I just noticed a big problem. Since i was watching a tutorial for 3d core, there is something that went wrong in my code. For smooth rotation I used Quaternion and lookdirection but i think because of that my enemy is rotating 90 on y axis making the enemy invisble. What can i do to correct my script. Here’s my waypointmover script,

Please help me solve the problem T-T

public class WaypointMover : MonoBehaviour
{
    //Stores a reference to the waypoint system this object will use
    [SerializeField] private Waypoints waypoints;

    [SerializeField] private float moveSpeed = 2f;

    [Range(0f, 15f)] //How fast enemy will rotate once it reaches its waypoint
    [SerializeField] private float rotateSpeed = 4f;

    [SerializeField] private float DistanceThreshold = 0.1f;

    //Current waypoint target that the object is moving towards
    private Transform currentWaypoint;

    //The rotation target for current frame
    private Quaternion rotationGoal;
    //The direction to the next waypoint that the enemy needs to rotate to
    private Vector3 directionToWaypoint;

    // Start is called before the first frame update
    void Start()
    {
        //Set initial position to the first waypoint
        currentWaypoint = waypoints.GetNextWaypoint(currentWaypoint);
        transform.position = currentWaypoint.position;

        //Set the next waypoint target
        currentWaypoint = waypoints.GetNextWaypoint(currentWaypoint);
        transform.LookAt(currentWaypoint);
       
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = Vector3.MoveTowards(transform.position, currentWaypoint.position, moveSpeed * Time.deltaTime);

        if (Vector3.Distance(transform.position, currentWaypoint.position) < DistanceThreshold)
        {
            currentWaypoint = waypoints.GetNextWaypoint(currentWaypoint);
            //transform.LookAt(currentWaypoint);
        }
        RotateTowardsWaypoint();
    }

    //Will slowly rotate the enemy towards the current waypoint it is moving towards
    private void RotateTowardsWaypoint()
    {
        directionToWaypoint = (currentWaypoint.position - transform.position).normalized;
        rotationGoal = Quaternion.LookRotation(directionToWaypoint);
        transform.rotation = Quaternion.Slerp(transform.rotation, rotationGoal, rotateSpeed * Time.deltaTime);
    }
}

Quaternion.LookRotation has a second overload that takes an ‘up direction’, ergo, which way is up when calculating the rotation that points (or more accurately, rotates towards) your direction.

By default this is Vector3.up, which make sense in 3d where Y is up. Though less so in 2D when often towards the screen, aka, Vector3.back is technically ‘up’ with respect to your game’s perspective.

Though I remember in some situations needing to add the calculated rotation to the default rotation (Quaternion.identity).

So you might have luck with either of these two:

Vector3 targetDirection = (currentWaypoint.position - transform.position).normalized;
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.back);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime);

// OR MIGHT BE
Vector3 targetDirection = (currentWaypoint.position - transform.position).normalized;
Quaternion targetRotation = Quaternion.identity * Quaternion.LookRotation(targetDirection, Vector3.back);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime);

I didn’t see you using directionToWaypoint or rotationGoal anywhere else so the values can become local to the method if that’s the case too.