Is there a way of using OnCollisionEnter() but allowing the object with the script to pass through any objects within a layer mask? I’m creating a turret, which occasionally shoots the gun barrel it is coming out of, I feel that the barrel needs a collider, as if the player shoots at it, I want there to be an impact.
The below code shows that I am able to find if something has a layer after the collision, but this isn’t hugely important.
void OnCollisionEnter(Collision col)
{
if(col.gameObject.layer != 8)
{
Instantiate (explosion, gameObject.transform.position, new Quaternion ());
ExplosionWork(col.contacts[0].point);
Destroy(gameObject);
}
else
{
Debug.Log("Hit " + col.gameObject.name);
}
}
Is there a clause that can be put in the OnCollisionEnter() parenthesise that will prevent a layer being collided with?
Thanks.