Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity Playmaker 3rd Person Arena Game- Pattern Randomization

Jul 19, 2022
About this tutorial

In this Unity + Playmaker 3rd Person Arena Game Pattern Randomization tutorial, I am going to show how to choose a random number and then use an Int Switch to play that particular pattern. If you still want to participate in this community game please join my discord. Base Game files: ► https://dr

Written Guide

This arena-game tutorial adds pattern randomization: instead of the boss cycling attack patterns in a fixed order, a randomizer state rolls a number and jumps to the matching pattern. The result is an enemy the player can't fully predict — built from one int variable, a Random Int action, and an Int Switch.

Step 1 — Have multiple patterns ready

The FSM now holds three pattern sets (one contributed by a community member via Discord — submissions welcome). The newest one is a simple rotate that spawns four fireballs at once, one from each side, waits briefly, loops, then runs the same sequence in the opposite direction. Color-coding the states pays off here: green for rotation, orange for fireballs, purple for loop-backs — at a glance you can see what each block does.

Step 2 — Create the randomizer state

Add a new state named Randomizer. Rewire the flow so the initial wait state (two seconds, at the very start only) leads into Randomizer, and every pattern's final transition loops back to Randomizer instead of chaining into the next pattern. Then create an int variable named random int, left at its default of zero since the randomizer will set it.

Step 3 — Roll the number

In Randomizer, add a Random Int action with a min of 1 and max of 3 (or 1 to 20 if you have twenty patterns), storing the result in random int. One checkbox will bite you if you miss it: Inclusive Max. Unchecked, the roll only ever lands on 1 or 2 — the max value is excluded. Check it so pattern three actually gets picked.

Step 4 — Route with an Int Switch

Add an Int Switch comparing random int with three cases. A roll of 1 fires a new pattern one event, 2 fires pattern two, 3 fires pattern three — add each event and its transition (Playmaker warns about missing transitions until you do), wiring them to the corresponding pattern states. Two settings round it out: check No Repeat, so the same pattern never plays twice in a row — after pattern one it must go to two or three — and leave Every Frame off, since the switch fires once and hands control to the chosen pattern.

Step 5 — Shorten the loops and test

Each pattern was set to loop 30 times, which makes testing tedious — drop the loop counts to 2 so patterns hand back to the randomizer quickly. Run it and watch the sequence: pattern two, three, two, three, then one — random order, no immediate repeats. The full flow is wait, roll a number, switch to that pattern, play it, and return to the randomizer forever. Adding a fourth pattern later is just one more switch case and event.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →