Throwing the ball
We can now start building our game mechanics. The first step will be a script to throw the ball. The plan is that, when a new shot is available, the ball will appear at the bottom of your screen. The user taps and flicks the ball on the screen to throw it. This launches the ball into the 3D space and we will detect if the ball collided with the basket goal for a score. The stages of game play are:
- Ready: The ball is waiting for player input to play it, disable its Rigid body
- Holding: The player is dragging the ball (flick is in process)
- Throwing: The ball is travelling with physics
We will track the launch speed and direction of the throw as well as other properties that let us adjust characteristics of the ball and its throw.
Ready ball
To begin, in your Project Assets/ARPlayBall/Scripts
folder create, a new C# script named ThrowControl
and open it for editing. First, we'll write the following code that resets the ball to its ready state:
File: ThrowControl.cs
using UnityEngine...