- Home /
Raycast not ignoring layer
I asked this question before, but I edited it and for some reason it desapeared. I have a problem. I have a child object with a collider and the father is creating a ray. I need the father's ray to ignore this collider but it is not working. The ray starts from inside the childs collider, which I believe it might be the problem. I can't use the IgnoreRaycast layer because I need this child object to be picked up by other rays. I'm setting up the ray like this:
void Start()
{
layer = LayerMask.NameToLayer("Touchable");
mask = 1 << layer;
mask = ~mask;
//Initial Positioning
yDir = mytransform.TransformDirection(Vector2.up) * rayCastRange;
hitLocalDown = Physics2D.Raycast(mytransform.position, -yDir, rayCastRange, mask);
if (hitLocalDown)
{
mytransform.position = hitLocalDown.point + hitLocalDown.normal * distancer;
}
}
I've read about this for a while and this should work, but it doesn't and I don't know why.
EDIT: I'm a moron, I had: mask = ~layer; insted of: mask = ~mask;
Now it works.
Comment