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.

The “Real” Method

Today’s Objective: Improve the coin toss by actually throwing the coin from the hand to the target point.

The Design:

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.

The Code:

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:

Using this initial velocity, the object will travel along the arc we calculated and hit the target spot, assuming it hits nothing mid-flight

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store