- Home /
How to stop projectile collider (is trigger) from colliding with other colliders (also is trigger)
How can I disable my projectile from colliding with other IsTrigger enabled colliders?
My project is currently setup as this:
I have a projectile with a Collider2D with IsTrigger enabled (for detecting when I hit something).
Then I have a Player with two Collider2D:
- A "normal" collider with IsTrigger disabled: For checking for movement, getting shot, etc - Another collider that has IsTrigger enabled: For checking for objects the player can interact with
Problem:
When I fire a enemy projectile toward the Player it collides with the Player IsTrigger enabled collider and never reaches the "normal" collider.
Projectile has a script containing OnTriggerEnter2D function that detects collision.
Answer by Marioooo · Feb 04, 2020 at 07:49 PM
Hello! if this is the first time you use physics layers then it will be a bit difficult to understand basically you have to separate the two colliders of the player into two gameobjects. the trigger collider must be a child of the main player gameobject.
then create three new layers:
Player (for the player gameobject)
PlayerInteraction (for the player child gameobject, this controls the player interaction with objects)
Bullet (for the bullet gameobject)
Then set the collision matrix to avoid the bullet to collide with the player interacion layer.
https://docs.unity3d.com/2018.1/Documentation/Manual/LayerBasedCollision.html
Hope this Helps!
Answer by Neidty · Jul 30, 2021 at 04:35 PM
I set it up exactly like this and its not working.
I have an object like a building with a mesh collider on the layer "Unit" which it actually should collide with.
This building has like an aura on a child gameobject with a sphere collider on the layer "detection" and isTrigger=true,
I fire a projectile with sphere collider on the layer "projectile" with isTrigger=true
I where in Project>settings>physics>layer Matrics -> uncheck colliding the layer detection to any other else layer.
The projectile stops at the aura.
What am i doing wrong?
Your answer
Follow this Question
Related Questions
2D colliders not colliding 2 Answers
2D Getting Arrow to stick to what it has collided with 1 Answer
Bullet Trail not destroying on collision 0 Answers
FixedJoint2D Setting the connected anchor to the point of contact between two objects. 1 Answer
Character slows down when running against a wall (2D) 1 Answer