Car Door with Animations
In depth learning on Behaviour Models is found in this course in Motive Academy.
- 1 Overview
- 1.1 Setup
- 1.2 Create the Animations
- 1.2.1 Trunk_Lid_Open
- 1.2.2 Trunk_Lid_Close
- 1.3 Set Up Storyflow
- 2 Related Articles
Overview
In another recipe, we use Grabbables and Joints to make a car’s doors openable (see https://motiveio.atlassian.net/wiki/spaces/USDK/pages/1008533751). This approach is not as great for the trunk, however, as most trunks are automated and open with a click. In this recipe, we’ll create Unity animations that automatically open and close the rear door.
Setup
Make sure to follow the setup steps in https://motiveio.atlassian.net/wiki/spaces/USDK/pages/1008533751 to ready the Prefab
Add a “Trunk Lid” Motive Scene Object to the Trunk_Lid node in the car Prefab
Create the Animations
This document assumes you have a basic understanding of Unity’s animation system and can create simple animations. This is a good starting point if not.
We’ll create two Animation Controllers that use the same clip to open and close the door. The “close” controller simply plays the clip backwards. We won’t walk through the creation step here, but here is what the two Animator Controllers look like:
Trunk_Lid_Open
Trunk_Lid_Close
Note that this one uses the same animation clip, but played with speed -1. For testing, make sure these two Animators are stored in a Resources folder so that they can be targeted by Storyflow:
Note that animations like these can also be deployed as an Asset Bundle, but for testing it’s quickest to load them directly from the Resources folder.
Set Up Storyflow
Create a Unity Asset Catalog
Add Trunk_Lid_Open and Trunk_Lid_Close (just the names):
Create a Unity Animation Catalog
Link two animations to these assets:
Trunk_Lid_Close is being edited here to show the link to the underlying Unity Asset.
Now you can use these animations at any time in your Storyflow Scripts using the Apply Effect Resource. In this example, we open the door then close it again 5s later:
Related Articles