void Update(){
//
if(dragging){
Ray ray = new Ray(transform.position, -Vector3.up);
Vector3 dir = -Vector3.up * 10;
RaycastHit hit;
if(Physics.Raycast(ray.origin, dir, out hit, gridLayerMask)){
print("object hit, layer = " + hit.collider.gameObject.name);
///ABOVE PRINTS DESPITE OBJECT RETURNERD NOT BEING IN LAYERMASK!!!!!!!
}
}
}
The grid layer, “grid”, is layer number 9. The floor layer, which is on the object being returned is on layer 8, “floor”. “floor” is not included in the gridLayerMask on the single instance I have.
Edit. Also, when is place the offending object, floor, on floor layer, which is being called incorrectly… When I switch it to another layer, say Default, it is still called. Very odd.
@Dantus ,
Hm. I am not sure, can check later when on computer. In the meantime tho, I see in the docs it converts a layerMask value to an int. why is this relevant here?
public static bool Raycast(Vector3 origin, Vector3 direction, RaycastHit hitInfo, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers);
You are passing a layermask as the distance parameter
Just put in a distance param and it will work. You dont need to use mask.value, it’s implicitly an int
Also why are you using dir when ray already has a direction; and dir being 10 units long is pointless, because Vector3(0,-1,0) and Vector3(0,-10,0) function the same
It’s a bit value for the masks. 1 << 9 is not 9, it’s the binary number 0001 0000 0000, which is 256. You can set a collision mask either as 256 or as mask |= 1 << 9;
Thanks, that makes sense. However, while it did stop calling a collider on a layer not part of mask, it is not calling object in layer mask. ??
I have double checked everything. The layerMask, is assigned to only receive “grid” layer. Object collider I am trying to detect has a collider and is on grid layer. My ray is casting in the proper direction, its distance is infinity, so I am unsure the issue now. Totally puzzled.
??
EDIT. Ok, so I ticked off the trigger of grid, and it receives. I thought a trigger could receive raycast hits. No?