- Home /
Use trigger with player but have a collider with everything else?
Hi, I have a crate that uses a trigger to detect when the player hits it. Is there any way I can make it collide normally with all other objects? My player has a tag 'Player'. Thanks.
Yes, you just disable 'isTrigger'. Why can't you just use normal collision to detect the player?
Answer by Anxo · Jan 07, 2012 at 04:30 PM
I would nest a game Object with a collider of the same size inside the crate. Set the original collider to "isTrigger = false" and the new object inside the create to "isTrigger" So it would be like having 2 boxes, one is invisible but has a trigger that is inside the visual box. Tell the player to physics.ignoreraycast the collider on the visual box and bingo.
This answer is perfect if you change thing. Just tweak the layer collisions to ignore the player on the parent object. Set the child object to a detectable collision layer. No need for fancy pants raycasting.
Answer by Peter G · Jan 07, 2012 at 04:53 PM
I would suggest a Layer-based ignore collision method. Place 2 colliders on top of each other. 1 is marked as a trigger, the other is solid. Create 3 layers:
-Player (layer the player in this one)
-PlayerOnlyTrigger (for the trigger)
-Collider (the regular collider)
Obviously naming can be changed, but its just the idea of it.
Now go to the Physics settings, "Edit/Project Settings/ Physics" And you'll see the layer collision matrix.
Turn player on for EVERY layer EXCEPT COLLIDER:
Collider is true for EVERY layer EXCEPT PLAYER (The first bullet point should also do this for you.)
PlayerOnlyTrigger is false for EVERY layer except PLAYER.
Then work out your game logic as usual. In the OnTriggerEnter() you don't have to worry about checking if its the player either because you can only collide with the player anyway.
(if I could!)
This is definitely the neatest way to do this.
Answer by WoodyDRN · Aug 08, 2012 at 10:09 AM
Good posts! I had this problems too, the solution I used was to:
1) Create a MESH Collider on the gameobject with isTrigger DISABLED, then the gameobject is solid, and you can't walk through it.
2) Then I added a BOX Collider on the same gameobject and set isTrigger ENABLED.
Now the BOX collider will trigger any script with functions OnTriggerEnter and OnTriggerExit.
Your answer
Follow this Question
Related Questions
Undefind tag? 0 Answers
Check Trigger Collision's Name/Tag 1 Answer
Reaching a gameobject from its collider 3 Answers
Collision, tags, and triggers 1 Answer