Rupert Stamp
Rupert Stamp

Reputation: 117

2D/Top Down Enemy Follow

I am trying to make my Enemies follow the player in a simple top down 2D fighting game in Unity

At the moment, the following script seems is not working for 2D, as the enemies "Flip" to face the player and also seem to be behaving in 3D. What is a simple alternative to make the enemies follow the player?

LookAt is causing the issues here i think..

     transform.LookAt(Player);


 if(Vector2.Distance(transform.position,Player.position) >= MinDist)
 {
     transform.position += transform.forward*MoveSpeed*Time.deltaTime;
 }

Upvotes: 2

Views: 3214

Answers (1)

maZZZu
maZZZu

Reputation: 3615

The simplest way is to construct a vector from enemy to player and make the enemy move along it:

transform.position += (player.transform.position - transform.position).normalized * MoveSpeed * Time.deltaTime;

Upvotes: 4

Related Questions