Simple Enemy Movement - [DM Build Jam]

Stadia Name: ekelrock
Package Name: Simple Enemy Movement
Package Description: Easily add quasi-random movement to your enemies. Includes player tracking, node-based routes, speed options, and other config properties.
Showcase Game: Play it here

Want you enemies to roam around an area til player’s arrive to chase? How about a guard that wanders the halls in a random pattern? If so, this is the package for you. It’s designed to be super simple to set up, there are a handful of config options to customize how you enemies move, and it can be easily integrated with other packages/blueprints.

SETUP:

  • Install the “Simple Enemy Movement” package from the community tab.
  • Drag the “Moving Enemy Template (with Tracking Trigger)” template into your world for an example of how it works.

HOW IT WORKS:
This package is based largely on Andy’s “Pet Duck” package – the movement code is completely written from scratch but the core concept is the same.

There is an invisible ball at the bottom of the enemy and, on each frame, it decides what to target and uses an impulse to move toward the target. The “enemy” is all contained within a locator that follows the invisible ball around. The ball can be set to target players and set to randomly cycle through an array of locators when no players are nearby.

This package also contains a slightly modified version of Nomaki’s “Entity Health” package to make the enemies killable by default.

OPTIONS:

Show all config options On the Enemy templates there is a script called "enemyMotionScript" with the following properties:
  • physicsEntity - The entity (ball) that rolls around allowing the enemy to move.

  • physicsEntityVisible - If true, the physicsEntity will be visible.

  • followLocator - A locator that will match the position of the physicsEntity. All enemy parts should be a child of this entity.

  • followPositionOffset - A vertical offset between the followLocator and the position of the physicsEntity.

  • staticSpeed - Speed of the enemy when moving between node locators.

  • randomizeStaticSpeed - If true, the staticSpeed will change randomly based on additional properties.

  • staticSpeedChangeInterval - Frequency, in seconds, between changing the staticSpeed.

  • minStaticSpeed - Min speed of the enemy when moving between node locators.

  • maxStaticSpeed - Max speed of the enemy when moving between node locators.

  • trackingSpeed - Speed of the enemy when tracking a player.

  • randomizeTrackingSpeed - If true, the trackingSpeed will change randomly based on additional properties.

  • trackingSpeedChangeInterval - Frequency, in seconds, between changing the trackingSpeed.

  • minTrackingSpeed - Min speed of the enemy when tracking a player.

  • maxTrackingSpeed - Max speed of the enemy when tracking a player.

  • staticPositionNodes - An array of locators. The enemy will move between these randomly when not tracking a player.

  • nodeTargetTime - The amount of time, in seconds, that the enemy will move toward a given locator before choosing a new one.

  • nodeChoiceDelay - The amount of time, in seconds, between stopping moving toward a node and choosing a new one.

  • restrictDistanceFromStartPos - If true, the enemy will move toward its starting position once it reaches a certain distance.

  • maxDistanceFromStartPos - The distance from the enemy starting position before it will turn back.

  • retreatWhenHurt - If true, the enemy will move away from players when its health is below a certain value.

  • retreatHealth - The lowest health value of the enemy before they begin to retreat.

ADDITIONAL OPTIONS / NOTES:
In addition to the core movement options on the Enemy templates, you can “connect” locators using the “nodeConnectorScript”. This script has a single property called “connectedNodes” that accepts an array of locators. An enemy that visits a node with this script will randomly select one of the connected nodes as its next destination. This way you could make an enemy traverse a long hallway without getting stuck, or have it wander around obstacles in a random pattern.

The physicsEntity (ball) included in the Enemy templates is too large to go up voxels at slow speeds. You can change the “mass” of the ball in its properties bag or try swapping out the mesh for a smaller ball. Adjusting the speed can also help. Basically there’s gonna be a bit of trial and error to get it working how you like, but that’s half the fun :slight_smile:

WANT MORE FEATURES?
I think this could be a pretty useful package for a lot of creators so if you’ve got ideas for improvements or features you’d like added, give me a shout on the discord.

And, as always, here’s a little GIF of it in action. This enemy will only track a player within the bounds, otherwise they randomly choose between locators and move between them.

5 Likes

i like it

1 Like