Adding Motions
Now that we have our first three animations loaded, we need to delve a bit deeper into the GameCore animation system. This will also be our first steps into GameCore's powerful motion blending system.
Animations versus Motions
On the previous page, we added 3 unique animations to our character. Animations are self-contained, meaning that they play 'as is' and are not modified by the engine, nor can they be. When you tell the engine to play an animation, it will play automatically at the same speed irregardless of what is occurring in the game. This is useful in certain cases, but for most situations, you will want to be able to manipulate the animation, potentially slowing it down, speeding it up, masking certain areas of the animation or otherwise changing it's default behavior.
For a complete list of the available GameCore OPR Properties that are related to Animation, please check the following page:
Properties Reference | Animation | LoadAnimation
Introducing Motions
Motions can be thought of as 'Animations with Properties'. Any time you add an animation to a model, you may want to consider adding a motion as well, as this gives you a bit more fine-grained control over how that animation is used in your game.
To add a motion to an object, simply add the following to your object's OPR file:
AddMotion MyMotion <- the name of the motion
MotionAnim AnimationName <- the name of the animation this motion is referencing
For our character setup, we want to add a motion for each animation that we loaded previously. The basic version of tihs is shown below:
AddMotion IdleMotion
MotionAnim Idle
AddMotion WalkMotion
MotionAnim Walk
AddMotion RunMotion
MotionAnim Run
For each of the motions, you simply give it a name (I tend to append 'Motion' to the end of the Animation name), and then tell the engine which Animation the motion is referencing.
Now, if we just let the motion 'as is', they would behave exactly the same as simply loading the animations like we previously did. However, the cool part comes when we start adding a few additional parameters to the Motions, which let us configure and begin to have control over the motion's playback from in-game.
Using Child Motions
The final motion that we want to add to our character is our 'move' motion. What this means is that we are going to bundle the above 3 animations into a single motion called 'move' that we will use to animate our character in-game using what are known as 'Child Motions':
AddMotion Move
MotionChild IdleMotion
MotionChild WalkMotion
MotionChild RunMotion
With the above, we now have a single motion called 'Move' that we can called from script using the PlayAnim() function that will automatically switch between the idle, walk and run motions.
Using MotionVariables
Motion Variables are a powerful mechanism for exposing control over your motions / animations to script. For example, you can define a single variable called 'speed' that gets updated from script, and the engine will automatically switch between different animations accordingly.
Let's take a look at how this is done.
As mentioned above, we have setup our 'Move' animation with 3 child motions, idle, walk and run. In order to tell the engine how we want to determine which of these child motions will be active at one time, we simply add a motion variable to each child motion and give the motions a range that will be used for switching.
There are several types of Motion Variables that we can use to affect our motions:
MotionScalarVar [variable name]
MotionSelectVar [variable name]
MotionTimeVar [variable name]
To start, we'll focus on the second option (MotionSelectVar), which is used to dynamically switch between animations. We'll cover the others at a later point.
MotionSelectVar
MotionSelectVar is used to expose a variable that will be used to determine whether or not this motion is to be active or not.
Using our above example, we have 3 motions defined - IdleMotion, WalkMotion, and RunMotion that we wish to be able to switch automatically based on the player's speed. We can do so by defining a Motion Variable called 'Velocity', like so:
MotionSelectVar Velocity
Adding this line to each of our child motions automatically defines a variable that we can then modify from script using the SetMotionVariableFloat() function.
So, our 3 motions with our new Motion Variable added now look like so:
AddMotion IdleMotion
MotionAnim Idle
MotionSelectVar Velocity
AddMotion WalkMotion
MotionAnim Walk
MotionSelectVar Velocity
AddMotion RunMotion
MotionAnim Run
MotionSelectVar Velocity
Simple enough no? Hopefully you're following along with me so far, because now is where things start to get fun ;}
As you may have noticed in the above motion definitions, we now have a Motion Variable called 'Velocity', but no actual definitions as to what exactly is supposed to happen when this variable is modified.
Luckily, GameCore provides two properties to help us out:
MotionSelectMin [float]
MotionSelectMax [float]
By combining a Min / Max value with our Motion Variable, we can direct the engine to automatically switch between our motions at runtime by simply modifying a single variable from script!
Here is our updated motions, with the min / max variables added:
AddMotion IdleMotion
MotionAnim Idle
MotionSelectVar Velocity
MotionSelectMax 0.2
AddMotion WalkMotion
MotionAnim Walk
MotionSelectVar Velocity
MotionSelectMin 0.2
MotionSelectMax 3.15
AddMotion RunMotion
MotionAnim Run
MotionSelectVar Velocity
MotionSelectMin 3.15
Let's walk through what we've done.
- First, we have an Idle motion that is set to play if Velocity is less than 0.2
- Secondly, we have a Walk motion that is set to play if Velocity is between 0.2 and 3.15
- Finally, we have a Run motion that is set to play if Velocity is higher than 3.15
The value's that I have defined here are entirely arbitrary, you can adjust them according to how fast you want your character to move in-game (and likely will want to modify them once we get the character playable in the next step).
You can have any number of motions parented together like this. For example, you might want a fourth motion called 'Sprint' that applies at an even higher value than the Run motion and so on.
Work-In-Progress Character OPR
To finalize, here is our current work-in-progress character OPR:
OPRP
#Load our primary character object
LoadObject MyCharacter.fbx
# load the various animations
LoadAnimation Idle Idle.FBX
LoadAnimation Walk Walk.FBX
LoadAnimation Run Run.FBX
# setup the basic motions
AddMotion IdleMotion
MotionAnim Idle
MotionSelectVar Velocity
MotionSelectMax 0.2
AddMotion WalkMotion
MotionAnim Walk
MotionSelectVar Velocity
MotionSelectMin 0.2
MotionSelectMax 3.15
AddMotion RunMotion
MotionAnim Run
MotionSelectVar Velocity
MotionSelectMin 3.15
# setup our parent motion
AddMotion Move
MotionChild IdleMotion
MotionChild WalkMotion
MotionChild RunMotion
At this point, our basic character & animation setup is ready to test in-game, so next up, we'll look at attaching the character controller and modifying a few of the basic settings!
Printer-friendly version- Login to post comments
- PDF version
