I’m using this to move my enemy towards my player
transform.position = Vector2.MoveTowards(transform.position, Player.transform.position, step);
But how do I stop it when it collides with my player?
I’m using this to move my enemy towards my player
transform.position = Vector2.MoveTowards(transform.position, Player.transform.position, step);
But how do I stop it when it collides with my player?
Hello ayockel90
Put on condition the line you’ve wrote by checking if the distance is major than a value:
float minDistance = 1.2f;
void Update ()
{
if (Vector2.Distance(transform.position, Player.transform.position) > minDistance )
{
transform.position = Vector2.MoveTowards(transform.position, Player.transform.position, step);
}
}
This should do the job, adjust the minDistance to the value you like.
Hope it helps!