You need to create a simple scene containing:
- 🏀 A ball (sphere) with a
Rigidbodycomponent - 🧱 A hoop (empty object with a trigger collider shaped like a ring)
- 🕹️ A throw button (press
Spaceor click a UI button) - 📦 A kinematic platform (a moving floor that pushes the ball)
On Space press, the ball receives an upward and forward force (AddForce with ForceMode.Impulse). Tune the values so the ball flies in an arc toward the hoop.
The ball must fall down if it misses the hoop. Use Use Gravity = true.
Create a platform that moves left and right (e.g., using transform.Translate). Give it a Rigidbody with isKinematic = true. The ball, if it lands on the platform, should move with it and not fall through.
When the ball enters the hoop's trigger:
- Print
"Score!"to the console - Reset the ball to its starting position
- Zero out its velocity (
velocity = Vector3.zero)
- Add a second ball with
isKinematic = true. It should not react to the throw or gravity, but when hit by the normal ball, it should push that ball away (check how collision works between a kinematic and a regular Rigidbody). - Experiment with different ForceMode values for the throw (e.g., Force vs Impulse) and observe the difference.
- To get a reference to the
Rigidbodyin code:
GetComponent<Rigidbody>()orpublic Rigidbody rb;(drag in the Inspector). - To reset velocity:
rb.velocity = Vector3.zero; - To move the platform:
transform.Translate(Vector3.right * speed * Time.deltaTime);and bounce off boundaries.