Reader small image

You're reading from  Unity 5.x Animation Cookbook

Product typeBook
Published inMay 2016
Reading LevelExpert
PublisherPackt
ISBN-139781785883910
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Maciej Szczesnik
Maciej Szczesnik
author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik

Right arrow

Using Quaternion.LookRotation() and Animator.SetLookAtPosition() methods to make characters follow an object with their gaze


Sometimes you need a character to look at an object in the game, for instance, at the camera. To do so, we can use two methods: Quaternion.LookRotation() and Animator.SetLookAtPosition(). We will cover both in this recipe (the second one is covered in the There's more... section).

Getting ready

To follow this recipe, you need a character with one Idle animation. You can also go to the Chapter 05 Character actions and expressions\Recipe 04 Using LookRotation and SetLookAtPosition methods to make characters follow an object with their gaze directory. Open the Example.scene scene there. You will find the HumanoidLookAt and HumanoidIKLookAt game objects there. The first one uses a generic LookAt() method and the second one uses the Animator.SetLookAtPosition() function. To see the effect, play the game, switch to the Scene View, and move the Target game object around (a...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Unity 5.x Animation Cookbook
Published in: May 2016Publisher: PacktISBN-13: 9781785883910

Author (1)

author image
Maciej Szczesnik

Not interested. Too busy with current game project. Source: Linkedin.
Read more about Maciej Szczesnik