addingAdding this Code worked for me.
private void Start()
{
// Store the initial rotation
initialRotation = transform.rotation;
// Get the NavMeshAgent component
navMeshAgent = GetComponent<NavMeshAgent>();
}
private void Update()
{
if (navMeshAgent.velocity != Vector3.zero)
{
// Apply the initial rotation
transform.rotation = initialRotation;
}
}