private void FixedUpdate() { collisionDetection.CastRayCast(); /* Since we are applying gravity constantly with our own physics, * we want to check if raycast hit anything, then we set the velocity.y back to 0, * so our ball don't fall through the platform. * We don't want to set velocity.y to 0 when bouncing, or else the ball won't bounce */ ballPhysics.ApplyVerticalCollision(collisionDetection); if (collisionDetection.collidedObject != null) // If our raycast system detects something { ground = collisionDetection.collidedObject.transform; // Set the ground variable to the detected gameobject } // If raycast hits something, we want the ball to bounce up if (collisionDetection.hasCollided) { ballBounce.Bounce(ref ballPhysics.velocity); HapticFeedback.Generate(UIFeedbackType.ImpactMedium); if (ground.GetComponent <PlatformController>() != null) { ground.GetComponent <PlatformController>().CallJiggle(); } } ballPhysics.ApplyPhysics(transform); }