Are Raycasts only used to check something? Why can't I use Raycasts to perform an action?

Hi! I’ve been playing around with Raycasts and SphereCasts and whatnot and currently i’m trying to perform an event for when a Ray has been activated, is this possible? Or are Rays only for checking or “see only” purposes?

Here is a picture of the Ray being activated when the ball is in sight, everything is working fine, the only issue is AddForce isn’t actually affecting the Ball.

And here is the code for what i’m trying to do.

   public void castRayCast()
    {
        float booster = 100;
        objectPos = transform.position;
        if (Physics.SphereCast(objectPos, rayRadius, Vector3.forward, out hitInfo, rayDistance))
        {
            rayAlive = true;
            Debug.Log("Raycast has hit " + hitInfo.transform.gameObject.tag);
            Debug.DrawRay(objectPos, Vector3.forward, Color.red);
            GameObject ball = pongPrefab;
            if (rayAlive)
            {
                ball.GetComponent<Rigidbody>().AddForce(transform.forward * booster, ForceMode.Impulse);
                Debug.Log("Ray is Alive!");
            }
            else
                Debug.LogError("Failed to bounce ball back");
        }
        else
            rayAlive = false;

    }

Any sort of help is appreciated! Thanks in advance :slight_smile:

You are not checking anything from the RaycastHit, just if it hit.

if(hitInfo.transform.CompareTag("Ball")){
	hitInfo.GetComponent<RigidBody>().AddForce(transform.forward * booster, ForceMode.Impulse);
}

This should check that your sphere hit the Ball, then get the RigidBody of it and apply the force.