My Enemy don't rotate in a direction player (NavMesh 2D)

Hello everyone, i d’ont know why my agent enemy don’t want rotate to my player, it’s in a NavMesh 2D.
You know why and how to resolution that problem please ???

The Code Enemy:

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.AI;

public class Enemy : MonoBehaviour
{
    NavMeshAgent agent;
    public float lifeEnemy = 100f;
    public Transform player;
    public GameObject effectsPrefab;
    public float effectDisplayTime;
    public float value;
    public float Damage;
    float cooldown = 0f;

    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        agent.updateRotation = false;
        agent.updateUpAxis = false;
        GetReference();
    }

    void Update()
    {
        agent.SetDestination(player.position);
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
        PlayerStats LifePlayer = collision.gameObject.GetComponent<PlayerStats>();
        if(cooldown <= 0)
        {
            if (LifePlayer != null)
            {
                LifePlayer.TakeDammagePlayer(Damage);
            }
            cooldown = 1f;
        }
    }

    public void TakeDammageEnemy(float amount)
    {
        lifeEnemy -= amount;
        if (lifeEnemy <= 0)
        {
            Die();
        }
    }

    private void Die()
    {
        GameObject effect = Instantiate(effectsPrefab, transform.position, Quaternion.identity);
        Destroy(effect, effectDisplayTime);
        PlayerStats m = player.GetComponent<PlayerStats>();
        m.money += value;
        Destroy(gameObject);
    }

    public void GetReference()
    {
        player = MovePlayer.instance;
    }
}

In this code, it’s evident that you disable agent rotation (in line 21), but there’s no line of code where you manually rotate the agent towards the player.

i know yes, so i don’t know how do that, i’ve test few idea, but it’s not function :frowning:

How does your game look? I mean, along which axis do you want to rotate the enemy? In the title of the topic, you mentioned that you’re using an agent for 2D, so I’m a bit confused. It could be a side-scrolling platformer where you need to flip the character’s sprite, or it could be a top-down game where the character rotates along the z-axis.

sorry for time of reply, i’ve resolved my bug, it’s good now, thanks you for your help too :smile::slight_smile: