58-New Enemy Movement — Waypoint

YShu
Unity2D Game-Galaxy Shooter Dev Log
2 min readMay 21, 2021

In this post, a new movement pattern will be introduced to the current enemy. Once the enemy is spawned at a random position, it will move along a designed path until being killed.

First, a path (empty game object) is created, which contains three children points (empty game object, with rigid body and collider).

The three boxes show the intended positions the enemy will move along, from left to right.

After that, the movement method in the Enemy script is updated.

Then, on the created point under the path, a script is created to detect if the enemy has moved there or not using OnTriggerEneter. If yes, the enemy will move to the next point, and so on.

The last thing is to create the UpdatePoint method in the enemy script.

As the path points are not hardcoded, new paths can always be created, the number of points can be adjusted, and the new path can be passed in the MoveAlongPath function to change the enemy’s moving behavior.

--

--