Make raycast ignore hitbox?
So I have a box and I want to have a raycast coming out from the front to detect when a player is in front of it. I want to have the box hollow so I can put items inside it, but when I place a hitbox for the front of the box, the raycast hits that collider. How can I make the raycast ignore the colliders from the object that's making the raycast? Here's my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class OpenCrate : MonoBehaviour { private Animation animationone; private Animator animationtwo; public float raycastdistance; // Use this for initialization void Start() { animationone = GetComponent<Animation>(); animationtwo = GetComponent<Animator>(); } // Update is called once per frame void Update() { RaycastHit hit; Ray playerdetectray = new Ray(transform.position, Vector3.forward); if (Physics.Raycast(playerdetectray, out hit, raycastdistance)) { if (hit.collider.tag == "Player") { if (Input.GetKeyUp(KeyCode.E)) { Debug.Log("Opened crate"); animationone.enabled = true; animationtwo.enabled = true; } } } } }
Your answer
Follow this Question
Related Questions
How do you detect a mouse button click on a Game Object? C# 2 Answers
Adding collision to Raycast hit 0 Answers
Collider does not always detect OnTriggerEnter 2 Answers
Raycast collisions being detected along a non-existent curve(?) 1 Answer
Why are my Physics.RayCast not showing the collsion with the Ground? 0 Answers