- Home /
Detect Collision Direction
Hi, I'm in the middle of programming my first game in Unity, and in a long time. I've done quite well with reserve knowledge form high school up to this point. I'm stuck currently trying to figure out an efficient way of detecting where a collision is taking place on my characters rigidbody.
I want to be able to detect when the play has be crushed by a block so that I can cue up a squishing animation and have the player be killed. Any tips or ideas would be greatly appreciated. I don't currently have any code for this issues, but am using Rigidbody controllers for character movement and gravity. I'm also most comfortable with C# and that is currently what I'm using to play all animations, though if I need to use javascript for this one detection I'm comfortable enough with it to program it in that language too. Just would prefer to keep everything C# for clean code.
Thanks,
Tyler Janke
I havn't done this, but maybe there is some information in the collider? ContactPoint.point
http://docs.unity3d.com/Documentation/ScriptReference/ContactPoint.html
http://docs.unity3d.com/Documentation/ScriptReference/ContactPoint-point.html
then take the point vector $$anonymous$$us the center of the collider object vector, and that should give you a vector direction the collision came from in reference to the model's center.
Collider API : http://docs.unity3d.com/Documentation/ScriptReference/Collider.html
API search 'point' : http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=point
You could also use separate colliders, ie have a box collider for the body and another for the head.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Enemies Jump at Random with Coroutines 2d (C#) Error. 0 Answers
OnCollsionEnter2D not getting called 1 Answer