5SD064 – Enemy movement visualization

Today’s post is about the movement for one of the enemies in the game Aetherial, shown to the right in the image below. Enemies in traditional Shoot’ em ups tend to move in simple predetermined patterns, not taking the player’s position into account. In Aetherial, the enemies will try to move towards the player while also moving in patterns, making them hard to hit. I’m going to employ AI techniques described in the book: Programming Game AI by Example, by Mat Buckland. The book describes steering behaviors for enemy Agents which takes their target position into account. Implementing the techniques is rather straightforward, but having to run the game to see the changes of the Agents can be a bit of a bother. This post describes the movement pattern for one of the enemies and a way to show the full movement path directly in the Unity Editor, making movement tweaking a breeze.SkySlug_movement

The enemies will be spawning in groups at an interval, and soars over the screen in a sine pattern towards the player avatar. When they are close enough, they switch from the normal sine pattern to start circling around the player avatar, shown below.

SkySlug_circle

When implementing this kind of movement where the enemies move towards the player while also following a pattern, it’s important to be able to visualize the path the enemies will follow the whole way. In unity there is a collection of things called Gizmos. Gizmos can draw debug information in the scene, lines and circles for example. Implementing the methods “OnDrawGizmos” and “OnDrawGizmosSelected” on a MonoBehaviour gives a place render this data. This allows immediate visual feedback for the designer, when tweaking parameters in the editor. Below is the current state of the movement pattern using gizmos to draw a series of lines along a sine wave.

Sine test

The final movement pattern is a bit more complex, hence why I started to visualize the movement. I want the enemy to start moving up and down the wave in large strokes, and gradually decrease the amplitude of the movement, the closer it gets to the player. Rough sketch below.  I think this will provide a bit more flavor to the basic used sine wave movement used in other Shoot ’em ups.

20180208_190915[1]

 

About Mattias Ramkvist

2017 Programming