Detect collision on certain area of an object
Hello,
I'm new to Unity and I have a question on game logic: I want to make a game where you can make a snow ball battle as throwing snow balls on each other.
How can I detect on which area of the models body is the impact of a snow ball? How can I get the force that arises on the impact?
Thanks for help :)
Answer by Naphier · Apr 19, 2016 at 10:08 PM
You'll need to add a collider to the specific body part (or one that surrounds the body part). I'm not quite sure what you're asking about "the force that arises on impact". If you have a rigidbody collider on both objects the impacted body will automatically have the correct amount of force applied to it. If you want to manually calculate this then that's a bit more complex and I'd suggest cracking open some physics books. Hope this helps.
Ok thanks, no that's good when the amount is calculated automatically. :)
How to add a collider, is it added to the whole model, to each bone or to the mesh?
Now let's say the impact is on the upper arm and I want to detect in detail on which area of the upper arm is the collision. How could I detect on which polygons of the mesh or which are of a bone the impact is?
Requires individual colliders for each area you want to check.
So I resume, please correct me if I'm wrong: I have to add rigidBody to the models and to the snowballs. For the snowballs I can use Sphere Collider. For the models I found $$anonymous$$esh Collider.
What I don't understand is how to use $$anonymous$$esh Collider for the purpose mentioned above (eg detect certain area of upper arm)? What do you mean with "individual colliders for each area you want to check"?
Answer by jgodfrey · Apr 19, 2016 at 10:08 PM
You'll want to use the OnCollisionEnter event, which is passed an instance of the Collision class. That class should contain everything you need including contact points, impact velocity, etc. Check out the docs here:
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.html
Your answer
Follow this Question
Related Questions
Which of Mulitipe colliders OnCollisionEnter ? 0 Answers
Evading obstacles 0 Answers
Trouble with detecting collision in the same frame to make smart labels 0 Answers
Collisions problem in VR 0 Answers