December 9, 2022
Note: The add-on provides comprehensive documentation as well. You can find it in Unity in path: MindPort → VR Builder → Add-ons → Animations → Documentation
In this VR Builder tutorial, we will create a process making use of the behaviors included in the Animations for VR Builder add-on. We will have a forklift driving to its destination, pick up a pallet of goods, then return to the initial position by driving backwards.
To move the forklift, we use the Follow Path behavior. This behavior allows to animate an object by having it follow a predetermined path, like for example a Bezier spline. To lift the pallet, we use the Animate Transform behavior instead. This works similarly to VR Builder’s original Move Object behavior, but is more powerful and provides more options, including the use of animation curves. Let’s get started!
This tutorial explains how to use the Animations for VR Builder add-on, which you can download from the Unity Asset Store. After downloading Animations for VR Builder it is time to define the workflow. In the beginning, we want to have a forklift driving to its destination. Then we want the forklift to pick up a pallet of goods, and finally return to the initial position by driving backwards. We assembled the Unity scene by creating a new scene and process with VR Builder's Setup Wizard. Then we used some free assets to create a warehouse-like environment. The forklift and pallet come from the Low Poly Forklift asset pack, while the containers come from Broken Vector's Low Poly Storage Pack. We scaled down the forklift to 0.3, but apart from this, the assets are ready to use. So just drag and drop them into the scene. No further modifications are needed to work with VR Builder.
Now that the Unity scene is set up, we can define the process. It consists of three steps: First, the forklift moves to the pallet. Then the forklift lifts the pallet. Finally the forklift moves back to the initial position. It makes logical sense for all these steps to be part of the same chapter. The result looks as follows:
If you need help in defining the workflow in the Process Editor, read the tutorial on the VR Builder GUI.
To make the forklift move in the first step, we add a Follow Path behavior to it.
First of all, we can see that the Follow Path behavior requires two scene object references to work. Object refers to the Unity game object that will be moved along the path. Path refers to the object defining the path to be followed and needs a Path Property implementation. The Path Property implementation can be an empty object, which will automatically be configured when pressing the Fix it button. By default, the Bezier Spline Path Property will be used, which allows editing the path as a Bezier spline.
If we select the Path game object after configuring it, we will see the spline in the scene. If the spline is not visible, enable gizmos in the scene view through the button on the top right.
The path is made of a single curve, so it has four control points: two anchor points and two handles. These can be selected by clicking on them and moved around like any object in the scene. Note how the curve changes depending on how the handles are moved.
However, we want the forklift to drive through the containers to reach the pallet. This requires the forklift to follow an “S” shaped path. Therefore, we will need to add at least one curve to our current path. Clicking the Add Curve button in the Bezier Spline component will append a new curve to the path, providing a new set of control points to work with. Now we can give the path the required shape. Note that it is possible to have a sharp angle on the middle point. That is because the default point mode Free allows both connected handles to be moved independently. To have a smooth transition, select it and change the point mode to Aligned or Mirrored. Both of these modes will force the handles to be aligned, resulting in a smooth curve. Mirrored will additionally ensure the two handles are the same length. This will in turn avoid abrupt changes of speed when transitioning from one curve to another (by default, velocity on bezier curves is not continuous).
We place the starting point of the path at the same position as the forklift’s origin. The end position is right in front of the pallet. Let’s then move the middle point roughly halfway between the other two. This will give us more control on how to shape the path. The final result for the path looks like this:
Once the path is configured, we can return to the behavior itself. There are a few options, but the only required fields are then ones for Object and Path. This means that if we press play now the behavior will work already. However, we probably want to extend the animation duration so the forklift doesn’t move too fast - let’s say set it to 5 seconds. Also, we might want to tweak the velocity curve so the forklift slows down before going under the pallet. This is a standard Unity animation curve: the horizontal axis represents the total animation duration and the vertical axis represents how far the object is along the path.
In this example, we decreased the acceleration at the end by providing more time (x-axis) for the last part of the curve (y-axis), so that the forklift slows down before picking up the pallet.
We don’t need to touch the other options for now, but feel free to explore more possibilities for customizing the path in the documentation of the Animations add-on. Now we can press play and observe how the forklift moves. You can always tweak the path in case it needs improvement.
Next, we want the forklift to lift the pallet. We want a predictable result, so we won’t rely on colliders and physics. Therefore, we will first parent the pallet to the fork, and then animate the fork to lift the pallet. We will use a Behavior Sequence for this. This is a special “container” behavior that executes a list of behaviors sequentially. Without this container behavior, all behaviors in a step would execute at the same time, which is not what we want here.
The first behavior in the sequence will be a Set Parent behavior. This simply allows to reparent a process scene object in the hierarchy. Let’s select the pallet as the object to be parented, and the fork as the desired parent.
For the lifting effect we use the Animate Transform behavior. This behavior makes it possible to lift both the fork and its child, the pallet. Animate Transform changes an object’s transform over time until it matches a specified target. Hence, it can be used to move, rotate or scale an object, also in combination. All three properties have their own animation curve, so it is possible to tweak those independently. In our case, we want the forklift to move upwards without any rotation or scaling. Therefore, only the fork’s position on the y-axis should change. To transform a specific object, we need a second game object - the final position provider to where the fork should move - with the required position, rotation and scale. Therefore, we create an empty game object, and rename it to Lift Top Position and give it the new y-axis coordinates.
We can then tweak the position of the animation curve in the behavior itself: by default it’s of ease in, ease out type, which should be fine for our use case. We can always modify its behavior if needed. The principle is the same as the one in the Follow Path behavior: horizontal is the animation duration, vertical is the progress between the start and the target values (in our case the fork’s height). This also means that giving the curve a wavy shape would make the fork go up and down; if we set its speed to very fast, it could for example represent some wobble at the end of the animation.
Let’s not forget to press play once in a while to check out how the animation is coming along!
The last step of our VR application is to move the forklift backwards while transporting the pallet. For this, we will use another Follow Path behavior which will follow the same path in the opposite direction. Let’s create a new step, add a Follow Path behavior to it and assign the Object and the Path.
We want the forklift to go from the end to the start of the path, so let’s select the Reverse option, which does exactly that. Note that the forklift will move backwards - by default, it follows the orientation of the path. We also need to increase the animation duration: it’s safe to assume that the driver would slow down while driving backwards, so let’s set that to 7 seconds.
If we press play, the forklift will drive to the pallet, pick it up, and then return backwards to the starting point. Well done!
This was only a brief introduction to the Animations add-on. Here are some suggestions to extend or improve the scene:
If we don’t like the forklift going backwards all the way, we could make it move forwards while following the same path in reverse. First, we need to turn it around. This can be done with another Follow Path behavior, which entails a path starting and ending at the endpoint of the initial path. Then, we create a Follow Path behavior and check Reverse as above, but also check Keep relative rotation. By doing so, the object will not snap to the orientation of the path (forward pointing towards the end), but will still rotate following the path’s shape.
We can easily unload the forklift by using the Set Parent behavior to unparent the pallet again. It is sufficient to leave the Parent field in the behavior empty. The forklift can then move away and the pallet will stay in place.
In this VR Builder tutorial you learned how to make an object follow a predefined path by using the Follow Path behavior and adjusting the position, rotation, and scale of an object over a period of time with the Animate Transform behavior. Now it is your turn to play around and get creative with animations. If you haven't done so yet, download the Animations add-on!