Question by
Oxidize_ · May 22, 2020 at 09:18 AM ·
2d2d gameenemy ai2d rotation
How to fix enemy's rotation (2D)
So I have a script assigned to my enemy for it to follow my player and the problem is it keeps rotating on the y axis, How can i fix this, Here's the script:
public Transform Player;
int MoveSpeed = 4;
float MaxDist = 10f;
float MinDist = 5f;
void Update ()
{
transform.LookAt(Player);
if (Vector2.Distance(transform.position, Player.position) >= MinDist)
{
transform.position += transform.forward * MoveSpeed * Time.deltaTime;
if (Vector2.Distance(transform.position, Player.position) <= MaxDist)
{
//Here Call a function for shooting
}
}
}
Comment