Game Development Reference
In-Depth Information
The missing random piece
We have our battle scene up and running, and when the player runs away he/she will still
be at the place on the map where the battle occurred. Wouldn't it be nice to also enter the
battle scene? So let's add that.
To keep things simple (you can always extend it later), we will just use a simple probabil-
ity to work out whether the player is likely to enter a battle while travelling. If a battle is
going to occur, we just figure out then where on the player's journey the battle will take
place. This way it looks random and catches the player off guard when it happens (if it
does, there's always a chance it won't).
Note
Alternatively, you could place empty game objects on the scene with colliders to change
the probability of an event occurring and have a script to start a battle if one happens.
Similar techniques are used in the Pokemon style games where deep grassy areas always
have a higher probability of a random battle occurring.
So to start off, we will add a couple of extra parameters to control the battle event probab-
ility in the MapMovement script, as follows:
int EncounterChance = 100;
float EncounterDistance = 0;
Tip
Ideally, the EncounterChance parameter should be controlled by some logic based on
the player's level and how dangerous the area of the world they are currently in, but you
can extend that later if you wish.
It is set to 100 for now to ensure the player will always hit the first battle to send him
home.
Next, in the FixedUpdate method where we track when a player taps or clicks on the
map to move, we check the probability of an event occurring. If that event occurs, then set
the EncounterDistance property as follows to denote when the event will occur
along the player's journey:
Search WWH ::




Custom Search