- Home /
The question is answered, right answer was accepted
RayCast can't detect GameObject at Player's feet
I have a Raycast that detects colliders, and if they have a certain tag, it executes a certain task, and makes text appear on the UI; however, when the GameObject (In this case a Capsule) is by the First Person Controller's feet, the Raycast is unable to detect the item. I've drawn a ray, and it seems it should be making contact with the collider. I've been unable to fix this issue, so I'm turning here for help.
void Update () {
sight = new Vector3 (transform.position.x , transform.position.y, transform.position.z);
Debug.DrawRay (sight, transform.forward, Color.green, 10);
landingray = new Ray (sight, transform.forward);
if (Physics.Raycast (landingray, out hit, DetectorLength)) {
if (hit.collider.CompareTag("item")) {
Directions.text = "Press E to Collect";
if (Input.GetKeyDown (KeyCode.E)) {
ic.PickedUp (hit.transform);
}
}
This is the code. I excluded some of the minor details, but I'm sure its easily understandable nonetheless. The script is located on the First Person Character GameObject, inside the First Person Controller.
Put the player on a separate layer and ignore that layer in the Raycast call (see: layer$$anonymous$$ask parameter).
Thank you! This has solved my issue, I've been trying to figure it out the past 2 days. 1 down, several to go.
Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Physics.Raycast doesn't hit anything even though Debug.DrawRay works 1 Answer
Multiple hit detection with Raycasting? 2 Answers
Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers
how detect "OnRaycastOut" 1 Answer