I have two scripts to open/close doors when pressed a key within collider range which works fine. Except the UI text (that prints ‘E’ on screen when looked at door) detects Box Collider (Is Trigger) as well as Mesh Collider which causes text to appear surroundings of the door. So, how can i specifically arrange only ‘Mesh Collider’ (door itself) to be hit by Raycast (for text) and not Box Collider?
void Update ()
{
Ray ray = Camera.main.ViewportPointToRay(new Vector3 (0.5F, 0.5F, 0F));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Reach))
{
if (hit.collider.tag == "Door")
Or if there is a better and simpler approach to open/close doors, i would like to hear.
Simple fix. If you want the door to respond to a walking player/character you could just make the box collider a foot or so high which will still get triggered by a walking players lower part of their capsule collider leaving the raycast clear to look at the upper section of the door.
Thank you @TwoTen for directing me to a good point about ignoring Triggers. I found out that i can disable Edit>Project Settings>Physics>Untick ‘Queries Hit Triggers’ which worked fine (hoping that won’t cause any problem in the future).
However when i add QueryTriggerInteraction.Ignore to my script like this:
if (Physics.Raycast(ray, out hit, Reach, QueryTriggerInteraction.Ignore))
{
if (hit.collider.tag == "Door")
Thanks, that was the issue. I added “1” to the script like this and it works:
Physics.Raycast(ray, out hit, Reach, 1, QueryTriggerInteraction.Ignore)
I have another question though; i’m assuming this “1” simply means “Layer 1”, am i right? But i realized only odd numbers works and layer context doesn’t make sense. That looks strange, could you please explain this to me?
I spend a lot of time in the documents, yet i sometimes look blankly at script references since i don’t have any coding background and i’m kinda new to this. Thank you for the patience (=
I honestly don’t know how to define bitmasks by code. Never had the need to learn haha.
I just use public LayerMask properies and let unity serialize it.