| Part 1: Character Animation And Movement Back to the overview |
||||||||||||
In this first tutorial we’ll start off by creating a dummy character and adding some background objects to the scene. We’ll create the basic character controls and movements and set up restraints to keep your character on the floor and prevent him from moving through objects. Next we’ll import the character and his animations and hook it up to the dummy character. These animations will include standing, running, shooting and jumping. Animation blending will make sure that all animation transitions will be as smooth as possible. This tutorial will introduce beginners to working with Building Blocks (BBs) and Parameters. We’ll set up conditions using Binary Switch BBs, use parameter operations and a Set Component BB to construct the desired translation of the character. You will learn how to use messages to activate the Enhanced Character Keep on Floor BB and how to set up the Object Slider BB for collision detection. After importing the animations it is necessary to create the right blended animations. Furthermore, to make the character animate properly you will need to set up conditions before messages can be sent to the Unlimited Controller BB. You’ll also have to think about priorities of animations within the Unlimited Controller BB to play the right animation. At the end of this tutorial you’ll have the main character up and running. If everything works out you will notice that the character will respond well even if the player is changing directions quickly. Smooth animation transitions and proper acceleration/deceleration will make the gameplay more realistic.
|
||||||||||||
1 The Data Resource In a new composition, let’s start by opening the data resource that came with this tutorial “tutorial_rsc.rsc”. Choose Resources > Open Data Resource and navigate to the folder in which you’ve unzipped the resource material. In this resource you will find all the necessary characters, objects, sounds and other material. • Navigate to the Characters folder and drag and drop “dummy_character” into a new composition. It looks like a box. This is a dummy character that we will use for control, collision detection and to make sure all animations of the real character work properly. • Navigate to the 3D Entities folder in the resource and drag and drop “city.NMO” into the scene. This file contains all sorts of background objects and one single light. Most objects in the scene are “prelit”. To make sure the objects that are “lit” or ”specular” look good as well, we imported a single light. If you take a look at the dummy character in the Level Manager you will notice that it and its hierarchy have initial conditions (IC). This is important because we need to make sure that its scale, position, orientation will remain normal while we test our scripts. Other objects still need attributes assigned to them, so they don’t have IC’s. It’s a good idea to save your work now. Don’t forget to “Save Version” regularly!
|
![]() |
|||||||||||
|
2
Control Script Now we’re going to create a script that controls the characters movement.
• Select the dummy_character in the Level Manager and press “S” to create a script on it. Let’s name this script “control”. Double-click on it to enter the Schematic View. Drag the top and bottom edge of the script to make some room (it’s going to be a big script). • Ctrl+double-click somewhere in the empty script to call the list of building blocks (BBs). Choose a Switch On Message BB and after that five Key Event BBs (four directions and jump). Connect the Switch On Message BBs behaviour input (bIn) to Start (the “thing” on the left side of the script). Double-click on the BB to edit its parameters. Change Message 0 to “movement_keys_on” and Message 1 to “movement_keys_off”. Connect the Received 0 behaviour output (bOut) to all the Key Event BBs On behaviour input (bIn) and the Received 1 bOut to all the Key Event BBs Off. Now we can activate and deactivate the controls with a message. Double-click all Key Event BBs to set the desired control keyboard keys, four for movement (the “W”, “A”, “S”” and “D” keys) and one for jumping ( “SPACE”), but we’ll ignore that last one for now. For each of the four Key Event BBs we will create a boolean (true/false) parameter so we can check if the key is pressed. Use Alt+L to quickly create a local parameter. Change the Parameter Type to boolean and name this first one “forward_pressed”. Do the same for the others, with other names of course. Connect these loose parameters to the corresponding parameter outputs of each Key Event BB. • Create a Parameter Selector BB for each of the four Key Event BBs. Connect the Key Event’s Pressed output to the In 0 and the Released output to the In 1 of the Parameter Selector BB. Edit the parameters of the Parameter Selector BB. Enter the maximum speed for your character (in meters per second) in the top parameter and the value 0 for the bottom parameter. Let’s say that our character runs at 4 m/s. Don’t forget that the float for backwards and left movement needs to be negative (-4). Create a local float parameter for each parameter output (pOut) of each Parameter Selector BB. Call them “desired_z_pos” and “desired_z_neg” for forward and backward movement and “desired_x_pos” and “desired_x_neg” for the right and left movement. Connect them to the corresponding pOuts. We’ll leave this as it is for now. |
|||||||||||
| 3
Translation Message Before we continue we need to setup the “translation” part in the bottom half of the script (if necessary make more room for it underneath the Key Event BBs).
• First we’ll add a Switch On Message BB, a Parameter Selector and a Binary Switch to check if we want the translation on or off. Enter “translation_on” and “translation_off” as the messages and connect the BB to Start. Change the pOut type of the Parameter Selector BB to boolean by double-clicking on it. Double-click on the BB and set the pIn 0 to “true” (checked). Connect the BBs as shown in the picture.
|
![]() |
|||||||||||
|
4
Translate Now let’s insert a Set Component BB, a Per Second BB and a Translate BB behind the Binary Switch BB. We’ll dynamically create a vector from three floats, then we’ll make this vector “per second” and then we’ll translate (move) the dummy_character over this vector. Rename the pIns of the Set Component BB to “x_translation”, “y_translation” and “z_translation”. Set the pOut type of the Per Second BB to “vector” (by double-clicking on it). Now you can connect the Set Component BB’s pOut to the Per Second BB’s pIn and connect it’s pOut to the Translate BB’s Translate Vector pIn (the left one). Edit the Translate BB: set the Referential to “dummy_character”. Loop back to the bIn of the Binary Switch BB to make sure that the Translation BB is on all the time (except for when you’ve sent the “translation_off” message of course!). |
|||||||||||
| 5
Calculate New Translation With the translation parameters in place, we can continue with the top part of our script. First we are going to calculate what you want to do: move forward or backward. We’ll keep in mind that when both keys (forward AND backward) are pressed at the same time, the character won’t move. Things will become a little more complex now.
• First insert an Identity BB next to the top (forward) Parameter Selector BB. All this BB does is output its input into a parameter. Now, let’s use a parameter operation (paramOp) to determine a temporary z translation. You create a parameter operation by pressing Alt+P. Set the inputs to “Float”, the operation to “Addition” and the output to “Float”. • We’ll use “shortcuts” ( direct links to a parameters elsewhere) to the desired z translations to replace the input parameters that are automatically created. First select the “desired_z_pos” parameter you already created, Ctrl+C to copy it to the clipboard and then press Ctrl+Shift+V to paste the parameter as a shortcut above the paramOp (alternatively, you can use the right-click menu for this). Do the same for “desired_z_neg”. Connect them to the inputs of the paramOp, deleting the existing links. Connect the paramOp output to the pIn of the Identity BB. Press Alt+L to create a new local float parameter, name it “z_translation_temp” and connect it to the pOut of the Identity BB. So, if you press forward this value will be 4, if you press backward it will be -4 and if you press both it will be 0. • Next, we’ll insert a Binary Switch BB. Create another paramOp, this time with two “Booleans” as input, “And” as the operation and “Boolean” as the output. Make shortcuts to “forward_pressed” and the “backward_pressed” the inputs and connect the result (true only if both inputs are true) to the pIn of the Binary Switch. • Add another Identity BB and a Variation BB. If the bOut of the Binary Switch BB is “true” the “z_translation_temp” parameter needs to be set to 0 before the translation can be calculated (the character will slow down and stop), if the bOut is false it can be connected directly to the Variation BB’s bIn. Create a shortcut to the “z_translation_temp” parameter above the Variation BB’s pIn and connect it. Now, if the parameter value changes at any time, the “Change” bOut of the Variation BB will be activated. |
![]() |
|||||||||||
![]() |
6 Change Translation To make the movement of the character increase and decrease with some acceleration and deceleration we’ll use a Linear Progression BB. • Insert it to the right of the Variation BB and connect its bIn to the Variation BBs Change output. Edit the parameters of the Linear Progression BB. Change the Time parameter to 500 ms (this will be your acceleration and deceleration time). Create a shortcut to “z_translation” above the A pIn and a shortcut to “z_translation_temp” above the B pIn. Now connect the Value pOut of the Linear Progression in the same “z_translation” shortcut. This way, the z translation will smoothly change into the new z translation. This behaviour needs to be looped. • Furthermore, to make sure that the value becomes 0 when it’s really small we’ve included another Binary Switch BB and a two paramOps. For the first one set the left Input to float (a shortcut to “z_translation”) and the right to “none”. Set the operation to “Absolute Value”, this convert negative values to positive values. Set the Output to “float” as well. The second one checks if this absolute float value is inferior to another float with the very small value 0.00005. Create a paramOp with two float Inputs, Inferior as the Operation and a boolean as Output. Insert the float output of the “Absolute Value” operation into the left float input. Change the second one to 0.00005. This output boolean is connected to the pIn of the Binary Switch BB; if the output is true then an Identity BB sets the z_translation directly to 0. To tidy things up, drag a Behaviour Graph (BG) around this part (everything behind the Parameter Selector BBs) of the script by pressing “g”. Name this BG “z_translation”. Don’t forget to connect the first Identity in this BG to the Start of the the BG! Now you can connect the bOuts of the two Parameter Selector BBs (the ones for forward and backward) to the bIn of this BG. Now you can copy and paste this BG for the x translation, you just need to implement the correct parameter shortcuts.
|
|||||||||||
| 7
Testing Your Script To test if this all works we need to create a little temporary Level script called “temp”.
• In the Level Manager, select Level and press “S” to create the script. Select the script and press F2 to rename it to “temp”. Double-click on it to open it in Schematic View. Insert two Send Message BBs and connect them to start. One message should be “movement_keys_on” and the other “translation_on”, both should have the dummy_character as Destination. Press Ctrl+T to activate Trace Mode. Now press Ctrl+Space to test your script. If everything is okay you can control your dummy_character with the keys you specified. There should be no problem when you use multiple keys at the same time or when you change direction. |
![]() |
|||||||||||
![]() |
8
Movement Contraints Now it’s time to setup two important constraints, one to keep the character on the floor and one to prevent him from going through objects.
• In the control script, let’s insert a Switch On Message BB (Message 0: floor_on, Message 1: floor_off) and the Enhanced Character Keep On Floor BB (Floor BB). Change the Detection Offset to 1 and the Character Extents both to 0. Connect the two BBs. Now we need to define the floors in our level. Go to the Level Manager, 3D Objects and select all the objects that have Floor in their name and the objects starting with Vehicle (use Ctrl to select multiple objects). Right-click and select Add attributes from the menu. In the Add Attributes Menu, open the Floor Manager section and select Floor, then choose Add selected. Add a “floor_on” Send Message BB to the “temp” script (destination: dummy_character). Give the script a quick test. You will notice that the dummy_character now has its full length above the floor and that it follows floor changes nicely. • Let’s return to the scripting. For the collision detection we need another Switch On Message BB (“objectslider_on” and “objectslider_off) and the Object Slider BB. Connect the two BBs. Go to the Level Manager and select all objects that need collision detection. Exclude the floors but include the vehicles! Press “G” to create a new group. Name it “objectslider_group”. Back in the Schematic View, double-click on the Object Slider BB to edit its parameters. Change the Radius to 0.45 and the group to the newly created “objectslider_group”. Add a “objectslider_on” Send Message BB to the “temp” script (destination: dummy_character). Test your script and you will see that your character doesn’t move through objects anymore! |
|||||||||||
| 9
Jumping The most difficult part of this script is next: jumping. Jumping is only possible when certain conditions are met: 1. Jumping must not be in progress. 2. The Enhance Character Keep On Floor BB must be off. 3. Falling must not be in progress. Next to this the player mustn’t be able to move or change his direction when he’s in the air (otherwise he could jump around corners).
• Let’s go back to the top part of the script. Insert a Binary Switch BB behind the Key Event BB that defines your jump-button. Create a new boolean condition called “jump_possible”. Set its value to “true” and connect it to the Condition pIn. Insert a Send Message BB, the Message should be “floor_off” and the Destination is still the dummy_character. Insert an Identity BB, set its pIn type to boolean and change its value to “false”. Create a shortcut parameter for “jump_possible” underneath this Identity BB and connect it to the pOut. • Now add a Bezier Progression BB, this will control the jump motion. Double-click on it to edit its parameters. Set the Time to 600 ms and B to 3. Now set the first control point of the Curve to x=0 y=0.8 (left, almost top), create a second (by double-clicking on the curve) on (0.3,1) and set the last to (1,0). Create a nice smooth curve; it will affect the smoothness of your jump. Loop this BB by connecting its Loop Out to its Loop In. Create a shortcut to “y_translation” underneath the “Value” pOut of the Bezier Progression BB and connect it. Connect all BBs as shown in the picture. |
![]() |
|||||||||||
![]() |
10
Jumping Again Create another Send Message BB behind the Bezier Progression BB. Set the Message to “floor_on” and the Destination to dummy_character.
• To check if your character is in the air or not we’ll use a Get Nearest Floors BB. Insert it and add a Test BB and an Identity BB. First edit the parameters of the Get Nearest Floors BB, set the Referential as the dummy_character. Create a local float parameter (Alt+L) and name it “floor_distance”. Connect it to the Lower Floor Distance pOut. Connect all bOuts to the Test BBs bIn. Create a shortcut of “floor_distance” above the pIn A of the Test BB and connect it. Double-click the Test BB to set the Test to Greater or Equal and the B to -1.1. Loop the False bOut back to the bIn of the Get Nearest Floors BB and connect the True bOut to the Identity BB. Set the pIn type of the Identity BB to “Boolean” by double-clicking on it. Set the parameter value to “true” and connect the pOut to another shortcut to “jump_possible”. This way the jump-possibility is only reset when the character is really on the floor. Don’t forget to connect all BBs properly. • Before we test the script it maybe a good idea to create a little shadow for your character so you can see the jumps better. Drag the hammer_shadow.BMP texture from the tutorial resource into your scene. Now drag a Simple Shadow BB (Visuals > Shadows) from the Building Blocks resource onto the dummy_character_bp (bodypart) in your Level Manager. Specify the right shadow texture and set the Size Scale to 6. Name the script “shadow” and test it. You are of course free to tweak the settings of the Bezier Progression BB the way you want them. Notice that when you jump while standing still you can start moving in mid-air. You can also change direction while you are in the air. We’ll fix this in the next step. |
|||||||||||
| 11
Movement In Air Contraint First delete all current links between the Pressed bOuts of the Key Event BBs for the four movement directions. That’s where we are going to insert some Binary Switch BBs.
• Create four of them and connect the Pressed bOuts of each Key Event BB to a Binary Switch BB. Connect the True bOuts to all the Parameter Selectors. Only when the condition is true the translation will be changed. Loop the False bOuts back to the Key Event BBs. This will make sure that when you keep a direction pressed while making a jump you will always continue in the direction your pressing. Create a shortcut to the “jump_possible” parameter in the lower part of the script directly above the pIn of the top Binary Switch BB. Connect this shortcut to all the pIns of the four Binary Switch BBs, replacing the existing links. Test your script again. WARNING If your jump_possible parameter is still "false" when you stop debugging your script, the character can't move when you restart your composition. |
![]() |
|||||||||||
|
12
Save Your Work Maybe now it’s a good idea to tidy up some of your scripting by creating some more BGs.
We’ve saved our progress up to now as tutorial_part1_halfway.CMO |
|||||||||||
| 13
Importing The Character Now we’re going to import the real character and setup all animations.
• In your tutorial resource, navigate to Characters and drag the character “TheHammerAK.NMO” into your scene. We’ve already hidden all biped body parts and adjusted the material to make the character more visible. It’s a good habit to set ICs on the character and its body parts and meshes to make sure they are not permanently deformed by animation or scripting. • Drag and drop all TheHammer animations (use Shift to select them all at once) from the resource onto your character. Create a script on TheHammerAK, name it “animation”. Now we’ll create a simple temporary script to position and orientate the character on the dummy character. Drag a Set Position BB and Set Orientation BB into the animation script. Because these BBs need to apply on TheHammer_ROOT (a dummy object we chose as our centre of gravity body part) we need to create Target Parameters on both BBs. Select the Set Position BB and press “T”. Edit the parameters of the BB. Set TheHammer_ROOT as the Target. Set the dummy_character as the Referential. Do the same for the Set Orientation BB but change the Dir vector to (0,0,-1) to make the character look in the right direction. When we create the camera-script in the next tutorial we will replace this with a different script, but this will do for now. This way your character won’t be able to change his direction just yet, he can only strafe.
|
![]() |
|||||||||||
![]() |
14
Creating Blended Animations Before we can insert an Unlimited Controller and specify all the required animations we first need to create blended animations. We need these to make the transitions between animations such as Run into Run_Shoot appear smoothly.
• Insert a Create Blended Animation 2 BB into your animation script. Select it and press “S” to edit the BBs settings. Uncheck Dynamic so we can keep the created animations after resetting the scene. Now edit the parameters of the BB and specify TheHammerAK_Run as Animation 0 and TheHammerAK_Run_Shoot as Animation 1.Connect it to Start. Run the composition. In the Level Manager, you can see that there’s a new animation called TheHammerAK_RunTheHammerAK_Run_Shoot. Do the same for the Air animation and the Backwards animation (you can reuse the same BB, delete in when you’re done). You can’t delete the animations you’ve used to create the blended animations, Virtools Dev needs them as referential. |
|||||||||||
| 15
Character Animation The animation script consists of three parts: 1. The Unlimited Controller BB. 2. Sending the animation messages under the right conditions. 3. Setting the blended animation factor.
• First we’ll insert an Unlimited Controller BB in the animation script, define the animations and the right order (0 to 5): Die, Air, Backwards, Run, Stand_Shoot and Stand. You can drag the edges of the columns if you can’t see the complete animation names. Also create the animation messages by clicking in the corresponding message text field and typing new messages: die_animation, air_animation etc. The Stand animation doesn’t need a message, it will play automatically when no other messages are received. Set the Warp Length for the Die and the Stand animation to 5, the others to 2 (those animations require a faster response). Set all framerates to 25 Fps. Important: Uncheck the Keep Character On Floor checkbox! Press Ok when you’re done. • Now create a local animation parameter (named “current_animation”) and a local message parameter (“current_message”) to keep track of the Unlimited Controller BB status. Connect them to the corresponding pOuts of the Unlimited Controller BB. Connect the bIn to Start. • Maybe it’s a good idea to hide the dummy character so we can inspect the animations better. In the Level Manager, hide the dummy_character by clicking on the eye icon. Do the same for the dummy_character_bp (bodypart). Select both and choose Set Initial Conditions from the right-click menu. You can run the composition to see your character play the Stand animation. |
![]() |
|||||||||||
![]() |
16
When To Play Which Animation Now we need to create conditions to determine which message to send at what time.
• Insert 5 Binary Switch BBs above the Unlimited Controller BB. With the first one we’ll check if the left button (fire) is pressed. Create a Mouse Waiter BB in the temp script, connect it to Start and create a boolean parameter underneath called: “left_button” and connect it to the corresponding pOut. Back in the animation script, create a shortcut to this left_button parameter above the first Binary Switch BB in your animation script and insert it in the pIn. Loop both bOuts into the bIn of the Binary Switch BB and connect the bIn to Start. If this condition is true, we need to send a message to the Unlimited Controller BB to play the Stand_Shoot animation. We’ll handle this later. Let’s continue with the other Binary Switch BBs (they’re not all this easy!). • The Run animation needs to be played when forward_pressed is true AND when backwards_pressed is false (otherwise the character would play the Run animation when he’s not moving). Create a paramOp, set its Operation to “And”, the inputs and output types to booleans. Create and connect a “forward_pressed” shortcut to the left pIn of the paramOp. Create another paramOp, set its Operation to “Opposite” and one input to boolean, the other to none and the output to boolean. Create a shortcut to “backward_pressed” and connect it to the left pIn of this paramOp. Connect the output of this paramOp to the right pIn of the “And” paramOp. Connect the pOut of the “Opposite” paramOp to the pIn of the Binary Switch BB and that’s it. Loop both bOuts. • Parameter operations are a very powerful and fast way to setup multiple conditions, so it’s a good idea to play around with them for a while. For the other conditions we will use the official short syntax for them: <pType> paramOp <pType><pType>. Example: <boolean> And <boolean><boolean>. The first parameter type (boolean) is the output type, “And” is the operation, the last two parameter types (booleans) are the inputs. |
|||||||||||
17 More Animation Conditions For the left and right movement we should send a run_animation message when: one of the two is pressed, but not when both are pressed. • Create <boolean>And<boolean><boolean> above the pIn of the Binary Switch BB. This will be our primary condition. Create <boolean>Or<boolean><boolean> to the left of the And paramOp to check if one of the two directions is true, <boolean>And<boolean><boolean> to the right of the And paramOp to check if both directions are true and insert the opposite: <boolean>Opposite<boolean> into the primary condition. • To test if you are jumping/falling or not we just have to create a shortcut to the “jump_possible” parameter of the control script above the last Binary Switch BBs pIn. For this one, if the False bOut is activated we can send the air_animation message (for the others it was the True bOut). This part is pretty hard, take a look at the screenshot if you can’t get it right.
|
![]() |
|||||||||||
![]() |
18
Sending The Message Now that we have created the conditions we can create four corresponding Send Message BBs : standshoot_animation, run_animation, backwards_animation, air_animation. Use Alt+T to create a This parameter. This parameter is always a “shortcut” to the owner of the script, in this case the character. Connect the This-parameter to all the Destination pIns of the Send Message BBs.
• Drag a behaviour graph (using “G”) around the BBs and rename it (F2): send_messages. Press “I” three times to create more bIns for your BG (while it is selected). Connect each BBs bIn to a bIn of the BG (!). Maybe it’s a good idea to create a BG for all those Binary Switch BBs as well. Let’s call it: check_movement. Press “O” to create four bOuts for that BG. Connect all this in a way that seems logical: the left button Binary Switch BBs True bOut must be connected to the “standshoot_animation” message, the forward and the left/right both need to be connected to the “run_animation” Send Message BB, the backward must be connected to the “backwards_animation” Send Message BB and the jump_possible False bOut must be connected to the “air_animation” Send Message BB. |
|||||||||||
| 19
Managing The Blended Animations With the Unlimited Controller BB and the Send Message BBs in place, the last thing to do is to manage the blended animations.
• First let’s insert a Set Blended Animation Factor BB in the lower part of the animation script and loop it. Create a shortcut parameter from “current_animation” (underneath the Unlimited Controller BB) and insert it into the first pIn of the BB. Rename the other pIn “blend_factor”. Now, when the left_button parameter changes from false to true, the “blend_factor“ needs to increase from 0 to 1 (this is the same as 0% to 100%). When it becomes false we’ll do the opposite. • Insert a Variation BB and change the pIn type to boolean by double-clicking on it. Connect a shortcut to “left_button” to this pIn. Loop the No Change bOut back to the bIn of the Variation BB. Connect the Change bOut to a new Binary Switch BB. Insert the same “left_button” shortcut as pIn. Connect the True bOut into the In 0 of a new Parameter Selector BB and the False bOut into the In 1 of the same Parameter Selector BB. Change the parameters of the Parameter Selector to 1 and 0 (remember: when left_button is true, the new blend_factor needs to become 1). Underneath the Parameter Selector BB, create a new float parameter called “new_blend_factor”. Connect it to the pOut of the Parameter Selector BB. • Connect the bOut to a new Linear Progression BB. Loop the Loop Out into the Loop In (pretty obvious). Set the Duration pIn to 200 ms. Create a shortcut to “blend_factor” above the A pIn and one to “new_blend_factor” above the B pIn. Connect them (deleting existing links of course). Connect the Value pOut of the Linear progression also to (the same) shortcut to “blend_factor”. Connect the bOut to the bIn of the Variation BB. • Drag a nice BG around the BBs and call it: blended animation. Connect it all to Start and that’s it. Give your script a go. Note: you need to hold the left mouse button to fire! |
|
|||||||||||
|
End of part 1. |
|||||||||||