- Home /
OnTriggerEnter with exact spot of collision
I want to set some traps in my game. The traps are really lethal and deal direct damage (like swinging blades, spikes etc.). I need to detect collision to trigger damage dealing and show particle effect for blood. I want it (blood) to show on exact spot where trap stroke player. In the same time I dont want the trap to interact physicly with player (for example spike comming out from the ground should not lift player up). The problem is:
to bypass physics collider should be set to IsTrigger.
but to get exact spot of collision I need to use OnCollisionEnter event which is sent only when the collider is not the Trigger (triggers send OnTriggerEnter).
Any ideas?
Answer by Bluestrike · Jun 12, 2012 at 07:49 PM
I use this to make my spears go trough an activating player without other players being able to pass trough: http://unity3d.com/support/documentation/ScriptReference/Physics.IgnoreCollision.html
So in theory you can use OnCollisionEnter to make the spears go off, when they hit the player, use the hit data for the blood and at the same moment turn the collider to ignore the player. Don't forget to undo the Ignorecollision when the player respawned.
It seems to work, thanks.
I'll just add that if you want to TURN BAC$$anonymous$$ ON the collisions you should use Physics.IgnoreCollision(col1, col2, false);
(with 'false' added as third argument).
Answer by Sapidus3 · Jun 17, 2012 at 07:33 AM
Just adding as a second solution:
Have the spikes use triggers. When they hit the player have them perform a raycast to get the exact position. There are different ways you can go about this depending on the geometry you are dealing with, but you should be able to get all of the information you need.
Your answer
Follow this Question
Related Questions
Colliding two GameObjects 1 Answer
Keep doing something while colliding 1 Answer
Colliders that do not collide... 1 Answer
Access other collider without use of Trigger collider. 1 Answer