- Home /
Question by
cesomark · Feb 20, 2017 at 09:43 AM ·
collisioncollision detectioncasting
BoxCast: Ignore Collisions with certain layers?
Hello,
i know it is possible to ignore collisions with raycasts. However i cannot find a solution for how to ignore collisions between my boxcast and certain layers.
In my case i have a plane that is surrounded by walls. I am casting several boxcasts on top of the plane that are supposed to tell me what they are hitting.
My problem is that close to the walls i simply get the collision with the wall, as they are obviously colliding, but i want to make it so that the wall is "invisible" for my box cast.
Is there a solution for that?
Thanks!
Comment
Answer by Kossuranta · Feb 20, 2017 at 10:20 AM
Looks like it works just like it does with Raycast using LayerMask. https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html
using UnityEngine;
public class MyScript : MonoBehaviour
{
public LayerMask myMask;
void Update ()
{
if (Physics.BoxCast(transform.position, Vector3.one, Vector3.down, Quaternion.identity, 100f, myMask))
print("Hit!");
}
}