EntityPlayAnimation - Create An Action That Plays An Animation
This guide provides instructions for setting up the EntityPlayAnimation action. In the sample app, once the avatar enters the trigger area, the character switches to the dancing animation state. When the avatar leaves the trigger area, the character switches back to the idle animation state.
The character switches to the dancing animation state when the avatar enters the trigger area. | The character switches to the idle animation state when the avatar leaves the trigger area. |
1. In this example, a trigger area is created and when triggered, an action plays an animation. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates an empty area that the avatar and other objects can pass through, a simple entity with a box shape is used instead of a 3D object. The entity does not have a RigidBody component. Right-click in the Hierarchy and select New Entity > Entity.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
B. Resize the collider to the desired size. In this example, the Half Extents field has been set to (2.5, .5, 2.5) for X, Y, Z.
C. The entity itself is currently set to Position (0, 0, 0) for X, Y, Z. In this example, the values for Position Offset are set to (0, -2, 0) for X, Y, Z to lower the collider to the ground.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
2. To add the EntityPlayAnimation action functionality
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select a desired trigger. In this example, the EntitySubscribeTriggerEnter trigger is selected.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select EntityPlayAnimation action in the dropdown menu. For the EntityPlayAnimation action to work, the name of the animation state that gets played needs to be added to the animate state to play field. In this example, the animation state name Dancing is added. The model that will be animated also needs to be added to the pick up specify execution entity field.
3. To add an additional EntityPlayAnimation action that will return the model to its initial animation state
A. Click "+" beside the selected module dropdown.
B. Click the type dropdown and select a desired trigger. In this example, the EntitySubscribeTriggerLeave trigger is selected.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select EntityPlayAnimation action in the dropdown menu. For the EntityPlayAnimation action to work, the name of the animation state that gets played needs to be added to the animate state to play field. In this example, the animation state name Idle is added. The model that will be animated also needs to be added to the pick up specify execution entity field.
4. To create the animation state graph, right-click in the Assets window and select New Asset > Anim State Graph.
A. Give the animation state graph a name.
B. Click the "Open Graph Editor" button to open the graph.
5. To add an additional animation state to the graph, right-click on the graph and select Add New State.
A. Rename the animation states. In this example, the Initial State animation has been changed to Idle. Confirm that the checkbox for loop is enabled.
B. In this example, the new animation state has been changed to Dancing. Place a checkmark in the loop checkbox.
6. To configure the model that will be animated
A. Click the "Add Component" button. Select Animation > Anim to add the Anim component.
B. Add the animation state graph that was created to the State Graph field.
C. Add an idle animation to the Idle animation state.
D. Add a dancing animation to the Dancing animation state.