Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Unity 5.x Animation Cookbook

You're reading from   Unity 5.x Animation Cookbook An advanced solution to all your Animation problems

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781785883910
Length 328 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Szczesnik Szczesnik
Author Profile Icon Szczesnik
Szczesnik
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Working with Animations FREE CHAPTER 2. Working with the Animation View 3. 2D and User Interface Animation 4. Character Movement 5. Character Actions and Expressions 6. Handling Combat 7. Special Effects 8. Animating Cutscenes 9. Physics and Animations 10. Miscellaneous Index

Detecting the hit location on a character


Another animation-related topic in combat is the hit location detection. This recipe shows how to easily detect hits to different body parts.

Getting ready

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.

How to do it...

To be able to detect hits for different body parts, follow these steps:

  1. Import your character with all the necessary animations to Unity. Place it on the scene.
  1. Create a new Layer and name it BodyParts. To do so, go to the Layers menu and choose the Edit Layers option, as shown in the following screenshot:

Adding a new Layer

  1. Create a new script and name it BodyPart.cs. Create only one public string bodyPartName variable in this script. We will...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images