Toss a Coin: Creating a Simple Distraction System (Game Dev Day 62)
With the guards pathfinding and patrol routes covered, I needed to give the player some way to alter the guards’ behavior so they can successfully sneak past them.
Enter the coin toss, a simple yet effective method of getting the guards out of their positions
So what is actually going on?
I am instantiating a coin prefab at the point a RayCast hits the floor. This is the same method used for movement, but I am using the RMB to perform this action.
Logically, other than the instantiation, I set a bool to only allow this to be used once per play session.
The coroutine to redirect the guards uses a tag (Guard1) to locate each individual guard, then set their destination to the coin’s current location.
There is also a few lines to ensure that their animations do not break because of the sudden new command.
Finally, in the GuardAI script, I added another bool to make sure the guards continue their normal patrols UNLESS a coin is tossed.