3rd Person in Unity and Playmaker - Base Enemy AI Roaming
In this 3rd Person in Unity and Playmaker tutorial, I'll be showing how to create and set up the base of an enemy ai roaming randomly between points. Then will make the enemy (a giant spider - yuck) into a Prefab so that I can add a lot of them. ► Download Playmaker at https://bit.ly/3dV8JzC ► Dow
This third-person tutorial builds base enemy AI: a spider that roams between four patrol points generated around wherever it spawns, using Unity's NavMesh for pathfinding and Playmaker for the state logic. Because the patrol points are computed relative to each spider, you can drop in dozens and each roams its own area independently.
Prepare the NavMesh and agent
Tag the spider as enemy. In the AI Navigation window, bake the NavMesh so the walkable areas turn blue. Add a NavMesh Agent to the spider and tune it: speed around 1 for slower movement, radius about 0.3, and height about 0.7 to fit the body. Through Playmaker's ecosystem browser, install the pathfinding package to get the NavMesh actions.
Generate patrol points at spawn
In an Init state, use Get Position to store the spider's start position as a Vector3. Then use Vector3 operators to add and subtract 5 on the X and Z axes four different ways, storing the results as position 1 through position 4, four patrol points around the spider. Doing this relative to spawn means every duplicated spider patrols its own surrounding area.
Idle, then pick a destination
In an Idle state, set the animator's idle-walk-run blend float to 0, add NavMesh Agent Animator Sync, and add a Random Wait from 0 to about 4 seconds. Then in a Get Destination state, use Select Random Vector3 with four options pointed at the four patrol points, store the choice as destination, and use Set Agent Destination to send the spider there.
Detect arrival and loop
In the moving state, set the blend float to 0.5 for walking, then use Get Agent Velocity every frame to read the velocity magnitude into a spider speed variable. Float Compare it against 0 with a tolerance of 0.1; once it is at or below that, the spider has effectively stopped, so transition back to Idle. The spider then waits, picks a new point, and repeats, roaming the four points forever. Save it as a prefab and duplicate it into an army of independently roaming spiders.





