- Home /
Answered in the comments.
How do I ignore trigger objects for collision?
I’ve attached eight objects around the perimeter of my player character, which determine if there is a collision, as well as the direction of the collision. When they collide only with normal, non-trigger objects, the collision is correctly registered, and when they collide with only trigger objects, the collision is correctly not registered. However, when they are colliding with both trigger and non-trigger objects simultaneously, the collision is incorrectly not registered, where it should register as it is colliding with a non-trigger object. How do I ignore trigger objects, while at the same time detecting non-trigger objects? Here the section of code that seems relevant:
bool colliding_with_trigger (Collider other)
{
if (other.gameObject.name == [[[trigger object name]]])
{
return true;
}
... [[[repeated for every trigger object]]] ...
return false;
}
IEnumerator OnTriggerEnter (Collider other)
{
if (true == colliding_with_trigger (other))
{
yield break;
}
... [[[the rest of the code for a collision]]] ...
}
$$anonymous$$aybe you can use the collision layer matrix ins$$anonymous$$d to solve your problem -> https://docs.unity3d.com/$$anonymous$$anual/LayerBasedCollision.html
You could use 3 layers for example: 1. CollisionRegisterLayer 2. TriggerLayer 3. NonTriggerLayer
and then set the matrix up so CollisionRegisterLayer doesnt collide with TriggerLayer... you would also need to put your objects on the right layers of course - dont know if that helps ...
$$anonymous$$aybe it's just very late here, but I read through your question 4 times and I am having hard time understanding what you are trying to perform exactly. Could you elaborate?