Question by
Oxidize_ · May 26, 2020 at 03:49 PM ·
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 any function U want Like Shoot at here or something
}
}
}
Comment