Creating an Enemy that Follows the Player in Unity.

Objective: Create a new movement type to make the enemy move towards the player.

In this case I create a new movement type. When the _movementType variable is equal to 3 I use the Vector3.MoveTowards() function. This function translates the gameObject passing as parameters the origin, the target and the distance. In this case I passed the enemy as an origin, the player as a target and the speed as the distance.

That’s all!!! We have an enemy that can move towards the player.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.