Wiki

Case Status
Log In

Wiki

 
Home ยป Samples»M2H Catch Egg»M2H Catch Eggs Game, Egg Spawn…
Index
Navigation
Community Wiki

M2H Catch Eggs Game, Egg Spawner Fsm

Spawn eggs from a random position around the SpawnObject, and increase the spawn rate over time to make the game more and more difficult

By far the most complex Fsm of this game. But it's still a very simple, so don't worry, this is all very simple to understand:

First thing, spawning an egg at a random position, this is done in sequence with two states "get a random position" and "spawn egg", you'll notice that the left and right limit to get a random position is hardcoded, we could do like in the User Input Fsm expose the right and left limit in the Fsm inspector for easy tweaking.

the random position is calculated first by defining where the egg is horizontally, that's how randomness, but we do want it to fall from the same height, so we use the SpawnObject as the reference for the height, store it position and inject on the x axis our random spawning point, once we have that ( stored in the "random position" variable), we can move the next state "spawn the egg" and actually instanciate a new egg from the prefab reference ( also defined as a variable, but you could directly reference it by dragging the prefab on the "create object" action.

Once the egg is spawned, the next tasks is the define the spawning rate, as this game will spawn eggs faster and faster to increase the difficulty. So in the "calculate next spawn time" we slowly but surely decrease the delay to call "SPAWN EGG" using simple math ( multiplying by less then 1 reduce the value) and we use this "spawn rate" as the delay value in the "send event" action.

Now the spawning loop is defined, but without first calling it when the fsm starts, no eggs would eve be spawned, so the Start state "spawn and egg immediatly" start the process by creating an egg and from then on the spawning will happen automatically, at an increasing rate.

Tags:

Last modified on 5/11/2012 3:04 AM by User.

  • RSS Feed