- Home /
Raycast still passes through even with layers!
public LayerMask layerMask;
void Update(){
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit, Mathf.Infinity, layerMask))
{
canUse = false;
Destroy(LockerClone);
LockerClone = Instantiate(Locker, hit.point, Quaternion.identity) as GameObject;
alreadyGotColor = false;
}
}
Even if there is a collider/wall infront of the player the raycast will still hit the object that has the layer mask on. Even if I put IgnoreRaycast on the walls it will still hit. This is an FPS game
You need to explain more about the issue here. And how do you calculate the layer$$anonymous$$ask?
So you problem is that the Raycast() is ignoring walls?
How are the walls constructed? Planes are one-sided for example.
What calculation do you do to set the layer mask?
How did you set the layers for the walls and the object?
What happens if you remove the 'layer$$anonymous$$ask' from your Raycast?
A layer$$anonymous$$ask is usually used to restrict a raycast to specific layers. It does not mask out, it masks in. So is the layer your wall is on included in the mask you set in the inspector. So are the layer you have the walls set to included in the mask?
yea raycasts actually have by default a layermask which is ~2
~2 means to cast against everything but items in layer 2 (the default layer for ignore raycast)
All of the walls are cubes.
I calculate the layermask on the Inspector mode
Walls are on "Default" layers while the blue objects are "Targetable" layer("Targetable" is a layer$$anonymous$$ask)
It will hit everything.
Your answer
Follow this Question
Related Questions
Ignoring Layer for OnMouseEnter/OnMouseExit 0 Answers
function OnMouseOver() ignore selected raycast 1 Answer
Can't Ignore a Layer when raycat 0 Answers
Ignoring an object (using raycast with layers) is not working 1 Answer
Shoot through walls 1 Answer