Node Based movement of Enemies

What?

I have been working on a system for node based movement for enemies. This makes it so that an enemies path is decided by putting out Game Objects in the scene called nodes. When an enemy has two or more nodes it will then move between the nodes in sequence at a set speed.

enemy-settings-2017-feb-9-012

How?

The script first makes sure that enough nodes are in the array for movement to work, otherwise it logs an error. If there are 2 or more nodes in the Nodes array, it first sets the position of the enemy to the first node in the list, and then sets the second one as the current target. Then I use the Vector3.moveTowards() function to move towards that node. When a node is reached, I increment the current target index, using modulo over the array length to wrap around if at the end, and then set that as the next target.

Why?

Before this, we had to make each enemy individually, with different scripts attached for different kinds of movement. I wanted to generalize the code for the enemies more, and after a bit of thought and some testing, I designed this node based system.

This way, making complex patterns for an enemy to move in is as simple as putting all the points of that path out into the editor window, and then dragging them all into the scripts ‘Nodes’ array. This makes testing of different paths a lot easier and faster, which makes testing different patterns faster and more approachable. Having this system removes the task of coding from the task of game design, so that they can be improved in parallell instead of being dependent on each other.

Moving forward, I have looked at how to make the movement and curvature of the path smoother withouth having to “spam” nodes. Another related thing I would like to do is to add properties to the nodes which affect how the enemies move to the next node, such as acceleration, subpatterns like moving to the next node in a wave patterns and so on. For the alpha however, this is enough to start testing which patterns are interesting, and which additions to the nodes that would be most interesting to implement next.

Advertisements

Author: weakman54

I make games.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s