Toss A Coin To Your W-… Security Guard. (Part 4)
In this post, I am building on Part 3 by making the coin fly along the arc before landing at the specified spot and distracting guards.
Today’s Objective: Improve the coin toss by actually throwing the coin from the hand to the target point.
I considered 2 different designs for “animating” the coin toss along the arc:
- Real method: Actually spawning the coin at the hand and setting its initial velocity to throw it to the point.
Pros: Realistic. Can hit physics objects during toss causing unintended distraction location. Simple code. Simple visuals.
Cons: Can hit physics objects during toss causing unintended distraction location.
- Fake method: Create a visual effect (particle effect or similar) that travels along the arc path, and the real coin spawns when it reaches the end.
Pros: Visually interesting. No physics/object interactions. Always hits the target. Customizable.
Cons: More complicated to implement. Probably Unrealistic.
In this post, I will be covering the “Real” method which I ended up going with. The “Fake” method will be in the next post for an alternative option.
When the right-mouse-button is clicked, I start a coroutine called “TossCoin()” which allows me to manage delays between different code during the toss. It is structured like this:
To skip the coin flying, I had it spawn in position at the Step 8 point, but now it is moved up to the Step 4 point prior to the already calculated coin flight time.
As many of these steps were completed in past posts/can be done yourself, I will show the new stuff.
For Step 4:
For Step 8 and 9:
I’ve ended up going with a design which, even using the “real” method, always hits the target point (passes through other objects). This is not what I originally planned, and I will probably change it later, but I had some difficulties dealing with unexpected effects coming from the coin hitting objects mid-flight, and landing in unintended locations. Also sometimes falling through the floor.