I have a Game Object with a script that has a function which raycasts four times around it to assess the Objects around it (Essentially, I have box colliders set up in a grid that check each other in a function). While these raycasts usually go through fine, there is a problem where the raycast keeps picking up certain objects (Walls, as planes in between the colliders) which have mesh collider turned off, and the raycast is set to pick up only layer 10, while these walls are on layer 12. Why is this happening, and how do I fix it?
With seemingly irrelated code removed, this is what I’m doing. print(colliderMapTile) returns an instantiated Prefab with it’s collider turned off with it’s layer set to 12.
var layermask = 1 << 10;
function updateSurroundingRooms(){
var cardinalDirection = new Vector3[4];
cardinalDirection[0] = transform.TransformDirection (Vector3.forward);
cardinalDirection[1] = transform.TransformDirection (Vector3.right);
cardinalDirection[2] = transform.TransformDirection (Vector3.back);
cardinalDirection[3] = transform.TransformDirection (Vector3.left);
for(var i : int = 0; i < 4; i++){
var hit : RaycastHit;
var colliderMapTile : GameObject;
if (Physics.Raycast (transform.position, cardinalDirection*, hit, layermask)) {*
-
colliderMapTile = hit.collider.gameObject;*
-
print(colliderMapTile);*
-
colliderMapTile.GetComponent("MapTileColliderBehaviour").roomChange();*
-
}*
- }*
}