Go to Top
  • No products in the cart.

How To Bring Your Character To Life In Vanda Engine – Part 2

Part 2: Animation Blending With BlendCycle And ClearCycle

(c) copyright Zehne Ziba Co., Ltd. For more information, please refer to copyright notice.

Introduction

In previous tutorial, you learned how to import a T-Pose mesh as well as its animations into Vanda Engine, setup its initial states, and save the character as prefab.

There are two different approaches for animations:

  • Looping Animation handled by BlendCycle() and ClearCycle()
  • One time animation handled by ExecuteAction and ReverseExecuteAction

In this tutorial, we use BlendCycle() and ClearCycle() to blend the animations of our character.

Inserting The Character

Run Vanda Engine. From the main menu, go to Prefab | Prefab Editor. Locate your character prefab and hit Insert button to insert your character into your level. In my case, Vanda Engine activates the stand animation of woman character. For more information about setting up the initial state of character, please refer to previous tutorial.

Adding A Light

I prefer to add a directional light to my level. From the main menu of Vanda Engine, go to Insert | Light…. Select directional light type, give your light a name, and specify a direction for your light. I prefer to insert my light in (10,10,10) position and choose a bright gray color. Hit OK button to insert your directional light into your level.

Insert-3D-Character-Add-Directional-Light-Image1

Inserting The Triggers

I’m going to insert three individual trigger into level. We will later assign our scripts to these triggers to activate stand, walk, and run animations of our character. Create your first box trigger by going to Insert | Trigger… menu, choose Trigger1 name, and press Create to add the trigger. Make sure that your trigger is still selected, go to Edit | Translate, and move your trigger to (-3, 0,2). Create two other triggers with the following properties:

  • Trigger2 => (0,0,2)
  • Trigger3 => (3,0,2)

Built-In Functions To Manage Animations

Before we write our scripts and assign them to our triggers, lets discuss about two important functions that deal with skeletal animations:

BlendCycle

bool     BlendCycle (char* prefabInstanceName, char* clipName, float weight, float delay)

This function interpolates the weight of an animation cycle to a new value in a given amount of time. If the specified animation cycle is not active yet, it is activated.

Parameters

  • prefabInstanceName: The prefab instance name that its animation clip should be blended.
  • clipName: The clip name of the animation cycle that should be blended. If your scene does not contain animation clip, set this parameter to “defaultClip”.
  • weight:The weight to interpolate the animation cycle to.
  • delay:The time in seconds until the new weight should be reached.

Returns

One of the following values:

  • true if successful
  • false if an error happened
BlendCycle() plays the animation in loop. In order to play the animation only once, use ExecuteAction() instead.

ClearCycle

 bool     ClearCycle (char* prefabInstanceName, char* clipName, float delay)

This function fades an animation cycle out in a given amount of time.

Parameters

  • prefabInstanceName: The external scene name that its animation clip should be cleared.
  • clipName: The clip name of the animation cycle that should be cleared. If your scene does not contain animation clip, set this parameter to “defaultClip”.
  • delay: The time in seconds until the the animation cycle is completely removed.

Returns
One of the following values:

  • true if successful
  • false if an error happened
Vanda Engine supports what is called Animation blending. In summary, it means making a smooth transition between several animations on a single character. Vanda Engine also supports mixing several animations together. Simply activate two or more animations with BlendCycle() and they will be mixed together by Vanda Engine

Writing First Script

In tutorial 11, we discussed about Lua scripting language and its dedicated IDE (please refer to Lua Scripting Language section). Before we write our first script, lets find the appropriate names that should be passed to our functions. In my case, it’s called 1_Samples_Female.

Prefab Instance Name: Look at the upper right corner of the editor. Under Prefab section, you’ll find the name of your character instance. We will pass this name to first argument of BlendCycle() and ClearCycle() functions.

Prefab-Instance-Name-Vanda-Engine-Image2

Animation Clip Name: Do you remember the animation files that we imported in previous tutorial? While importing an animation file, Vanda Engine creates an animation clip repository, names that animation clips based on the file name of animation file without .dae extension, and fills that animation clip with animation data imported from animation file. For example if your animation file name is walk.dae, your animation clip name will be walk. We will pass these animation clip names to the second argument of BlendCycle() and ClearCycle() functions.

Run sciTE, and write the following code to fade out the stand and sprint animations and fade in the walk animation:

Vanda-Engine-BlendCycle-ClearCycle-1-Image1jpgThis will fade out stand and sprint animation (if active) within 1 second and fade in the walk animation within 1 second. Save your script and make sure to include .lua extension at the end of your file name, return back to Vanda Engine, select Trigger1 object, hit Attach Script button, and in new dialog that appears, hit Trigger::Enter, locate Trigger1.lua and press Open. Vanda Engine should report that your trigger loaded successfully. Otherwise, return back to sciTE IDE, fix your script, and re-attach your script to Trigger1 trigger.

Attach-Script-To-Trigger-Vanda-Engine-Image4

Now we play-test our new script. Make sure that Physics debug mode is enabled (Modify | General PhysX Options… | Debug Mode), hit Play button, and enter Trigger1 trigger. In my case, stand animation fades out in 1 second and simultaneously, walk animation fades in in 1 second. Because sprint animation is not active, the following function has no effect and returns false:

ClearCycle( "1_Samples_Female", "Laura_sprint", 1.0)

Hit-Trigger-Vanda-Engine-Image5entering trigger 1 activates walk animation and deactivates stand animation

Similarly, write the following scripts to activate sprint or stand animations and attach them to enter events of trigger 2 and trigger 3:

Vanda-Engine-BlendCycle-ClearCycle-2-Image6Fade In sprint, Fade out stand and walk (if active)

Vanda-Engine-BlendCycle-ClearCycle-3-Image7Fade In stand, Fade out sprint and walk (if active)

 

arrow-leftPrevious Tutorial

Next Tutorialarrow-right

Let’s stay in touch!

Never miss a single tutorial, sign up for our monthly newsletter. You can unsubscribe at any time if you wish to stop receiving email newsletters from vandaengine.org

 

Simple Share Buttons