Raycast never detects a hit

For some reason, the following code never detects a raycast. I’ve checked the debug lines, and the other object is clearly being hit and has a collider. Additionally, the raycast is spawned from outside of the collider. Why isn’t it working?

            RaycastHit Hit;
            Debug.Log("Shooting");
            transform.LookAt(player, Vector3.up);
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
            Debug.DrawLine(Raycaster.transform.position/* + new Vector3(horzOffset, heightOffset, 0)*/, Armature.transform.forward * angleMult, Color.blue);
            if (Physics.Raycast(Raycaster.transform.position/* + new Vector3(horzOffset, heightOffset, 0)*/, Armature.transform.forward * angleMult, out Hit, Range)) {
                Debug.Log(Hit.transform.name);
                Hit.transform.SendMessage("rayHit", myTeam);
            }
            alreadyAttacked = true;
            Invoke(nameof(ResetAttack), timeBetweenAttacks);

Did you look at the API reference for Debug.Line? It takes two world-space position arguments, not what you passed it. It’s not Debug.DrawRay.

Also, you should ensure you’re drawing a line at the same distance you’re using for the query.

Ah, yes. I had switched them by accident. Either way, the ray is still clearly hitting the other object and not giving a response.

EDIT: Range was set to zero. Thanks for the help.

PSA: Set your range.

1 Like

Glad you got it working. Good luck with your project. :slight_smile: