Into the Cup
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 69 of 71.
Challenge
HardLet a slow marble drop into the cup.
- In
Hole, addvoid OnTriggerEnter(Collider other). - When
other.TryGetComponent(out Golf golf)andother.attachedRigidbody.linearVelocity.magnitude < sinkSpeed, log"In the cup in " + golf.strokes + " strokes!"and callother.gameObject.SetActive(false);.
Press Play and sink the marble: a fast one rolls over the cup. Then Check.
Try it yourself
using UnityEngine;
public class Hole : MonoBehaviour
{
[SerializeField] private float sinkSpeed = 3f;
// a slow marble drops into the cup, a fast one rolls over
}
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad4Coroutines
InvokeInvokeRepeating, CancelInvokeYour First CoroutineLoops in CoroutinesStopping CoroutinesRecap: Countdown10Project: Arena Escape
The ArenaHunters2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable WallPractice on your own: Unity playground