- Home /
Detect punch for humanoid characters
I am building a fight scene.
Right now Max(Humanoid AI on left) is punching thru me, Baldie (Humanoid character on right).
How can I build it so that:
Max does not punch thru Baldie
Baldie responds to punches whenever it is hit (collision detection)
Game is being built for an iOS app so resources are limited but please share your thoughts either way.
Long term I am trying to build a Mortal Kombat type game with many interactions between characters like this:
Answer by HarshadK · Oct 21, 2014 at 05:47 AM
You need to add a collider to your Max and Baldie character to make contact in them so that the punch thrown by Max does not go through Baldie.
Then you can check if the collision occured (OnCollisionEnter) to perform the action you require like you can make the Baldie react to the punch and throw a punch back at Max. For regular physics like Baldie being thrown back due to punch will be handled by the physics engine itself.
Look into colliders for more details on how to use them. You might also want to take a look at ragdolls.
I've added box colliders to both characters at the root level but the punches still pass through.
You need to add colliders to body parts of your characters in order for them to work like a collider on the hands of your characters, one colllider on the torso of your character and so on.
In your current box collider scenario the characters will not pass through each other since they have colliders on them but since there is no collider on the hand it will surely pass through the collider on the body of other character.
Also, how can I create physics like behavior so that Baldie is thrown back when it receives a punch? I tried adding a RigidBody component to Baldie but it did not have any effect.
Apply an Impulse force on the Baldie at the point of collision from the direction the punch came from or just in the normal of the point of collision.
Your answer
![](https://koobas.hobune.stream/wayback/20220613165543im_/https://answers.unity.com/themes/thub/images/avi.jpg)