2D Top Down, Enemy facing player slow rotation issue. Vector gets messed up after collision.

Hello everyone, the following is the code below for my top down shooter for the enemy. However I found a weird rotation issue where if I use the player to collide with the enemy, then the enemy has its rotation vector messed up. In a way if I spin the enemy somehow through colliding with it, then the enemy will face the player sideways and will keep trying to look at the player sideways instead of face forward. When the enemy gets close and is able to collide with the player on its own the vector seems to back to normal and the enemy will face forward again.

I feel like the main issue is in Update() part of the code where the Slerp and various other calculations are happening.

using UnityEngine;
using System.Collections;

public class EnemyScript: MonoBehaviour {

	public float EnemyHealth = 100;
	public float speed;
	public float Rspeed;
	public Transform player;
	public Transform target;

	void Update() {

		Vector3 vectorToTarget = target.transform.position - transform.position;
		float z = Mathf.Atan2 ((player.transform.position.y - transform.position.y), (player.transform.position.x - transform.position.x)) * Mathf.Rad2Deg - 90;
		Quaternion q = Quaternion.AngleAxis(z, transform.forward);
		transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * Rspeed);


	}

	void FixedUpdate () {

		GetComponent<Rigidbody2D>().AddForce (gameObject.transform.up * speed);

	}



}

Why is your enemy moving along the its up-axis and rotating around its forward-axis? I would except it to move along forward and rotate around up.

Anyhow: It is probably easier to use Quaternion.LookRotation than calculate the values yourself. The following code should do the same as your code:

Vector3 toPlayerVec = player.transform.position - this.transform.position;
toPlayerVec.z = 0.0f;
Quaternion q = Quaternion.LookRotation(toPlayerVec, Vector3.forward)*Quaternion.Euler(270,180,0);

Could someone please modify the script so that I could test it for the bug. Thank you.

I think I figured it out, my Rigidbody2D had 0 Angular Drag. Combine that with no gravity, I had physics forces constantly affecting the object when I hit it, thus causing it to go crazy and face me with its wrong sides. Thank you ChrisAngelMindmapfreak.