Zoe - Reacting to the user's presence

Tutorial

·

Beginner

·

+10XP

·

10 mins

·

(25)

Unity Technologies

Zoe - Reacting to the user's presence

In this activity we will program a character to react when the user approaches it.

Languages available:

1. The Animator Controller

You can launch custom animations with Zoe, either done inside Unity either embedded directly in a 3d model. In both cases you need to have an Animator Controller with the different clips and the transitions between them.


For this activity we have provided an animator that is already set. Go to the ‘Animations’ folder and double-click on Horse. The Animator window should open up and show the animations for the Horse:


Horse Animator

Horse Animator


From the start, the horse will be playing the ‘eat’ clip in a loop. Then as the user approaches the horse we want it to react so the animator will transition to the ‘idle_1’ clip.


For Zoe to be able to do this you need a transition condition of type ‘Trigger’ between clips. In this case the transition condition is already created (‘HorseUp’ Parameter on the previous screenshot).


The condition is set on the transition between the two clips (also called states). If you select the arrow you can see the Parameter ‘HorseUp’ in the conditions:


HorseUp condition

HorseUp condition


You can now go back to the Scene window. In the Hierarchy expand 'Activity 5' and select the Horse. In the Inspector window you can see the Animator component. Under Controller, you find the Animator you previously explored (Horse):


Animator Component

Animator Component


2. The Approach condition

Now let’s make the horse detect the user’s presence. First convert the Horse into an Interactive Object.


IMPORTANT: resize the Box Collider at the root of Horse(IO) that is automatically generated or remove it so that the user can properly approach the Horse.


Select the Proximity collider inside the Horse(IO) hierarchy, resize it and place it towards the horse head creating a zone around it where the user will be approaching it:


Horse Proximity

Horse Proximity


Duplicate the 'Empty' interaction and rename it ‘UserApproaches’. Add the ‘Approach’ condition under the ADD CONDITION list. It will already be set with the Horse(IO) as the Target Object:


Setting the Approach condition

Setting the Approach condition


Set a distance of at least 2m which will be the distance between the center of the Horse Proximity collider and the user's.


3. Launching the Animation

Inside the same interaction add the ‘Animation’ action. Set it to 'Play', then under 'Animator' drag the Horse (inside Visuals, the one with the Horse Animator attached); it will automatically detect the 'HorseUp' condition:


Animation action

Animation action


Press 'Play' and test approaching the horse. Adjust the distance of the Approach condition if necessary.


Complete this tutorial