Enemy leans back/ rotates when colliding with other game objects, any fixes?

locking rotation and position in rigidbody and adding is kinematic does nothing,
thanks

Imgur

Imgur

Imgur

public class ZombieController : MonoBehaviour

{

public NavMeshAgent agent;

public Transform player;

public LayerMask whatIsGround, whatIsPlayer;


//Patroling

public Vector3 walkPoint;

bool walkPointSet;

public float walkPointRange;


[SerializeField] private float minDistanceToPlayer = 0.5f;


//Attacking

public float timeBetweenAttacks;

bool alreadyAttacked;


//states

public float sightRange,

public bool playerInSightRange, PlayerInAttackRange;



private void Awake()

{

player = GameObject.Find("PlayerModel").transform;

agent = GetComponent();

}


// Update is called once per frame

void Update()

{

//check for sight and attack range

playerInSightRange = Physics.CheckSphere(transform.position, sightRange, whatIsPlayer);

PlayerInAttackRange = Physics.CheckSphere(transform.position, attackRange, whatIsPlayer);


if (!playerInSightRange && !PlayerInAttackRange) Patroling();

if (playerInSightRange && !PlayerInAttackRange) ChasePlayer();


}


private void Patroling()

{

if (!walkPointSet) SearchWalkPoint();


if (walkPointSet)

agent.SetDestination(walkPoint);


Vector3 distanceToWalkPoint = transform.position - walkPoint;


//walkpoint reached

if (distanceToWalkPoint.magnitude < 1f)

walkPointSet = false;

}


private void ChasePlayer()

{

transform.LookAt(player);

agent.SetDestination(new Vector3(player.position.x + minDistanceToPlayer, player.position.y, player.position.z + minDistanceToPlayer));

}


private void SearchWalkPoint()

{

//calculate random point in range

float randomZ = Random.Range(-walkPointRange, walkPointRange);

float randomX = Random.Range(-walkPointRange, walkPointRange);


walkPoint = new Vector3(transform.position.x + randomX, transform.position.y, transform.position.z + randomZ);


if (Physics.Raycast(walkPoint, -transform.up, 2f, whatIsGround))

walkPointSet = true;



}

You are telling the enemy to look at the player with transform.LookAt(player); this changes the rotation on all every axis. You can try setting just the enemies y rotation to rotate towards the player direction.