Another animation-related topic in combat is the hit location detection. This recipe shows how to easily detect hits to different body parts.
We are going to use a simple character with just one looped Idle
animation in this recipe. You can also use the provided example Unity project and go to the Chapter 06 Handling combat\Recipe 10 Detecting the hit location on a character
directory. You will find an Example.unity
scene there, with a Humanoid
character. Play the game to see the effect.
To be able to detect hits for different body parts, follow these steps:
- Import your character with all the necessary animations to Unity. Place it on the scene.
Adding a new Layer
- Create a new script and name it
BodyPart.cs
. Create only onepublic string bodyPartName
variable in this script. We will...