I just finished commenting Example 3: Limb Specific Animations
Here is the source code. It's pretty simple to do. There is very little effort in creating clean transitions like what is shown in the video posted above.
`Enhanced Animations
`Example 03: Limb Specific Animations
`---------------------------------------------
`by: Ron Erickson 23-Jan-07
`Setup
`------------------------------------------------
SYNC ON
SYNC RATE 0
SET DISPLAY MODE 1024,768,32
AUTOCAM OFF
`Load Objects:
`------------------------------------------------
`Load Character model
load object "media\ai.x",1
yrotate object 1,180
fix object pivot 1
load image "media\ai_D2.DDS",1
texture object 1,1
set object emissive 1,rgb(128,128,128)
position object 1,0,0,0
`Load Gun
load object "media\colt 45.x",2
load image "media\colt45.bmp",2
texture object 2,2
xrotate object 2,90
zrotate object 2,180
scale object 2,75,75,75
offset limb 2,0,0,-2,0
fix object pivot 2
glue object to limb 2, 1, 38
`Camera
POSITION CAMERA 35,65,100
POINT CAMERA 0,45,0
`SET THE DEFAULT ANIMATION PLAY SPEED
`************************************************
EnAn_SetDefaultPlaySpeed 15
`EXTRACT ANIMATION DATA FROM MODEL
`************************************************
`SYNTAX: EnAn_ObjExtractAnimation ObjID, FileName$, StartFrame#, EndFrame#
EnAn_objExtractAnimation 1, "Stand.anim", 0, 1
EnAn_objExtractAnimation 1, "Run.anim", 300, 318
EnAn_objExtractAnimation 1, "Walk.anim", 235, 259
EnAn_objExtractAnimation 1, "StepLeft.anim", 260, 279
EnAn_objExtractAnimation 1, "StepRight.anim", 280, 299
EnAn_objExtractAnimation 1, "Aim.anim", 554, 571
EnAn_objExtractAnimation 1, "Reload.anim", 682, 731
EnAn_objExtractAnimation 1, "Throw.anim", 319, 355
`LOAD ANIMATIONS
`************************************************
`SYNTAX: AnimID = EnAn_AnimLoad(Filename$)
An_Stand = EnAn_AnimLoad("Stand.anim")
An_Run = EnAn_AnimLoad("Run.anim")
An_Walk = EnAn_AnimLoad("Walk.anim")
An_Left = EnAn_AnimLoad("StepLeft.anim")
An_Right = EnAn_AnimLoad("StepRight.anim")
An_Aim = EnAn_AnimLoad("Aim.anim")
An_Reload = EnAn_AnimLoad("Reload.anim")
An_Throw = EnAn_AnimLoad("Throw.anim")
`CREATE OAC LINK TO OBJECT
`************************************************
`SYNTAX: oacID = EnAn_oacCreate( ObjectNo )
oacID = EnAn_oacCreate( 1 )
`LIMB HIERARCHY
`************************************************
`We need to know what limbs numbers go to the limbs that we want to control
`You can easily find out information about your limbs by doing something
`like this:
remstart
open to write 1,"limb data.txt"
for a = 1 to EnAn_ObjTotalLimbs(1)-1
write string 1, str$(a) + " = " + limb name$(1,a)
write string 1, "--------------------"
write string 1, " Parent Limb: " + str$(EnAn_ObjFindLimbParent( 1, a )) + " - " + limb name$(1,EnAn_ObjFindLimbParent( 1, a ))
write string 1, " Direct Children:"
for b = 1 to EnAn_ObjTotalLimbs(1)-1
if EnAn_ObjIsLimbChild( 1, a, b ) = 1 and EnAn_ObjFindLimbParent( 1, b ) = a
write string 1, " " + str$(b) + " = " + limb name$(1,b)
endif
next b
write string 1, " "
next a
close file 1
remend
`This model's hierarchy looks like this:
`Base
`|-Pelvis
` |-Spine
` |-ThighRight -> The rest of the model's Right Leg are children of ThighRight
` |-ThighLeft -> The rest of the model's Right Leg are children of ThighLeft
` |-Spine1
` |-Spine2 -> The rest of the model's UpperBody are children of Spine2
`When you want to control the model's upper body, you can simply refer to the Spine1 limb and include it's children
`All of the rest of the limb's actions should be set to what you want the lower body (movement) to do.
`These are the lower body limbs that I will need to apply my movement animation to
Limb_Base = 1 :`This specific limb
Limb_Pelvis = 2 :`This specific limb
Limb_Spine = 3 :`This specific limb
Limb_ThighRight = 4 :`This limb and all of it's children
Limb_ThighLeft = 12 :`This limb and all of it's children
Limb_Spine1 = 20 :`This limb and all of it's children
`This is the upper body limb that I will need to apply my action animation to
Limb_Spine2 = 21 :`This specific limb
`MODES
`************************************************
`This is just a couple of varibales to keep track of what action is currently happening
`There are two types of actions that can be happening on the model at one time.
`Movement Types:
Move_Stand = 0
Move_Walk = 1
Move_Run = 2
Move_Left = 3
Move_Right = 4
`Action Types:
Action_None = 0
Action_Aim = 1
Action_Reload = 2
Action_Throw = 3
`Current settings for each mode
MoveMode = Move_Stand
ActionMode = Action_None
`General Variables
`************************************************
transTime = 1000 : `This is just a variable that I will use for all of the transition times:
DoLoop = 1 : `Set animation to loop
NoLoop = 0 : `Do Not loop animation
IncChild = 0 : `Include all of the limbs child limbs
ExcChild = 1 : `Only use the specified limb
`PLAY THE STAND ANIMATION
`************************************************
`Begin by playing the Stand animation on the entire object
`SYNTAX: EnAn_oacPlayAnim oacID, Limb, AnimID, StartFrame#, CurrentFrame#, EndFrame#, loop, ExChild
EnAn_oacAnimTransition oacID, 1, An_Stand, 0, 0, 0, transTime, 1, 0
`Get the current time value.
time = timer()
`**********************
`Main Loop:
`**********************
DO
`OBJECT ROTATION
`************************************************
if inkey$() = "a" then turn object left 1,1
if inkey$() = "s" then turn object right 1,1
`ELAPSED TIME
`************************************************
`Get the amount of elspsed time since the last time check
elapsedTime = timer() - time
`Reset the time check
time = timer()
`UPDATE THE OAC
`************************************************
`SYNTAX: EnAn_oacUpdate oacID, elapsedTime
EnAn_oacUpdate oacID, elapsedTime
`LIMB BASED TRANSITION TO NEW ANIMATIONS
`************************************************
`SYNTAX: EnAn_oacPlayAnim oacID, Limb, AnimID, StartFrame#, CurrentFrame#, EndFrame#, TransTime, loop, ExChild
`Movement Animations
`-------------------------------------------------------------------------
`WALK:
`If user presses the up key, and character is not already Walking, then set the character to walk
if upkey() = 1 and MoveMode <> Move_Walk
EnAn_oacAnimTransition oacID, Limb_Base, An_Walk, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Base limb (with NO children) to Walk
EnAn_oacAnimTransition oacID, Limb_Pelvis, An_Walk, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Pelvis limb (with NO children) to Walk
EnAn_oacAnimTransition oacID, Limb_Spine, An_Walk, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine limb (with NO children) to Walk
EnAn_oacAnimTransition oacID, Limb_ThighRight, An_Walk, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Right Thigh limb (with ALL children) to Walk
EnAn_oacAnimTransition oacID, Limb_ThighLeft, An_Walk, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Left Thigh limb (with ALL children) to Walk
EnAn_oacAnimTransition oacID, Limb_Spine1, An_Walk, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine1 limb (with NO children) to Walk
MoveMode = Move_Walk :`Set Move mode to walk
`If there is no action happening on the upper body, then it is ok to set the upper body to walk too.
if ActionMode = Action_None
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Walk, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Walk
Endif
endif
`STEP RIGHT:
`If user presses the right key, and character is not already stepping right, then set the character to step right
if rightkey() = 1 and MoveMode <> Move_Right
EnAn_oacAnimTransition oacID, Limb_Base, An_Right, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Base limb (with NO children) to Step Right
EnAn_oacAnimTransition oacID, Limb_Pelvis, An_Right, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Pelvis limb (with NO children) to Step Right
EnAn_oacAnimTransition oacID, Limb_Spine, An_Right, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine limb (with NO children) to Step Right
EnAn_oacAnimTransition oacID, Limb_ThighRight, An_Right, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Right Thigh limb (with ALL children) to Step Right
EnAn_oacAnimTransition oacID, Limb_ThighLeft, An_Right, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Left Thigh limb (with ALL children) to Step Right
EnAn_oacAnimTransition oacID, Limb_Spine1, An_Right, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine1 limb (with NO children) to Step Right
MoveMode = Move_Right :`Set Move mode to Step Right
`If there is no action happening on the upper body, then it is ok to set the upper body to step right too.
if ActionMode = Action_None
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Right, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Step Right
Endif
endif
`STEP LEFT:
`If user presses the left key, and character is not already stepping right, then set the character to step left
if leftkey() = 1 and MoveMode <> Move_Left
EnAn_oacAnimTransition oacID, Limb_Base, An_Left, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Base limb (with NO children) to Step Left
EnAn_oacAnimTransition oacID, Limb_Pelvis, An_Left, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Pelvis limb (with NO children) to Step Left
EnAn_oacAnimTransition oacID, Limb_Spine, An_Left, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine limb (with NO children) to Step Left
EnAn_oacAnimTransition oacID, Limb_ThighRight, An_Left, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Right Thigh limb (with ALL children) to Step Left
EnAn_oacAnimTransition oacID, Limb_ThighLeft, An_Left, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Left Thigh limb (with ALL children) to Step Left
EnAn_oacAnimTransition oacID, Limb_Spine1, An_Left, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine1 limb (with NO children) to Step Left
MoveMode = Move_Left :`Set Move mode to Step Left
`If there is no action happening on the upper body, then it is ok to set the upper body to step left too.
if ActionMode = Action_None
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Left, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Step Left
Endif
endif
`RUN:
`If user presses the down key, and character is not already running, then set the character to run
if downkey() = 1 and MoveMode <> Move_Run
EnAn_oacAnimTransition oacID, Limb_Base, An_Run, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Base limb (with NO children) to Run
EnAn_oacAnimTransition oacID, Limb_Pelvis, An_Run, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Pelvis limb (with NO children) to Run
EnAn_oacAnimTransition oacID, Limb_Spine, An_Run, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine limb (with NO children) to Run
EnAn_oacAnimTransition oacID, Limb_ThighRight, An_Run, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Right Thigh limb (with ALL children) to Run
EnAn_oacAnimTransition oacID, Limb_ThighLeft, An_Run, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Left Thigh limb (with ALL children) to Run
EnAn_oacAnimTransition oacID, Limb_Spine1, An_Run, 0, 0, -1, transTime, DoLoop, ExcChild :`Set the Spine1 limb (with NO children) to Run
MoveMode = Move_Run :`Set Move mode to Run
`If there is no action happening on the upper body, then it is ok to set the upper body to run too.
if ActionMode = Action_None
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Run, 0, 0, -1, transTime, DoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Run
Endif
endif
`STOPPING:
`If no movement keys are being pressed and character is not already stopped, then stop
if upkey() = 0 and rightkey() = 0 and leftkey() = 0 and downkey() = 0 and MoveMode <> Move_Stand
EnAn_oacAnimTransition oacID, Limb_Base, An_Stand, 0, 0, 0, transTime, NoLoop, ExcChild :`Set the Base limb (with NO children) to Stop
EnAn_oacAnimTransition oacID, Limb_Pelvis, An_Stand, 0, 0, 0, transTime, NoLoop, ExcChild :`Set the Pelvis limb (with NO children) to Stop
EnAn_oacAnimTransition oacID, Limb_Spine, An_Stand, 0, 0, 0, transTime, NoLoop, ExcChild :`Set the Spine limb (with NO children) to Stop
EnAn_oacAnimTransition oacID, Limb_ThighRight, An_Stand, 0, 0, 0, transTime, NoLoop, IncChild :`Set the Right Thigh limb (with ALL children) to Stop
EnAn_oacAnimTransition oacID, Limb_ThighLeft, An_Stand, 0, 0, 0, transTime, NoLoop, IncChild :`Set the Left Thigh limb (with ALL children) to Stop
EnAn_oacAnimTransition oacID, Limb_Spine1, An_Stand, 0, 0, 0, transTime, NoLoop, ExcChild :`Set the Spine1 limb (with NO children) to Stop
MoveMode = Move_Stand :`Set Move mode to Stopped
`If there is no action happening on the upper body, then it is ok to set the upper body to stop too.
if ActionMode = Action_None
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Stand, 0, 0, 0, transTime, NoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Stop
Endif
endif
`Action Animations
`-------------------------------------------------------------------------
`AIMING THE GUN
`If user presses the left mouse button and character is not already aiming the weapon, then aim
if mouseclick() = 1 and ActionMode <> Action_Aim
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Aim, 0, 0, -1, transTime, NoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Aim
ActionMode = Action_Aim :`Set Action mode to Aim
endif
`RELOAD THE GUN
`If user presses the spacebar and character is not already reloading the weapon, then reload
if spacekey() = 1 and ActionMode <> Action_Reload
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Reload, 0, 0, -1, transTime, NoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Aim
ActionMode = Action_Reload :`Set Action mode to Reload
endif
`THROW
`If user presses the right mouse button and character is not already aiming the weapon, then aim
if mouseclick() = 2 and ActionMode <> Action_Throw
EnAn_oacAnimTransition oacID, Limb_Spine2, An_Throw, 0, 0, -1, transTime, NoLoop, IncChild :`Set the Spine2 limb (with ALL children) to Throw
ActionMode = Action_Throw :`Set Action mode to Throw
endif
`NO ACTIONS
`If no action keys are being pressed and character is not already doing no actions, then join the upper body's animation with the movement animation
if mouseclick() = 0 and spacekey() = 0 and ActionMode <> Action_None
`Get the current animation ID of what is playing on the lower body
CurrentAnim = EnAn_oacGetLimbPlayAnimID(oacID, Limb_Base)
`Get the current frame of the animation playing on the lower body
CurrentFrame = EnAn_oacGetCurrentFrame(oacID, Limb_Base)
`If move mode is not stopped. This is only because I can not use all frames of the "stand" animation
if MoveMode <> Move_Stand
EnAn_oacAnimTransition oacID, Limb_Spine2, CurrentAnim, 0, CurrentFrame, -1, transTime, DoLoop, IncChild
ActionMode = Action_None
else
EnAn_oacAnimTransition oacID, Limb_Spine2, CurrentAnim, 0, CurrentFrame, 0, transTime, NoLoop, IncChild
ActionMode = Action_None
endif
endif
set cursor 0,0
PRINT "Enhanced Animations"
PRINT "Example 03: Limb Specific Animations"
PRINT "By: Ron Erickson"
PRINT "visit: www.GameToolshed.com"
PRINT "--------------------------------------------------------------------------------------"
PRINT "This example shows differenr animations playing on different limbs of the same object!"
PRINT "Movement:"
PRINT "UPKEY = Walk, RIGHTKEY = Step Right, LEFTKEY = Step Left, DOWNKEY = Run"
PRINT "Actions:"
PRINT "LEFT MOUSE BUTTON = aim weapon, RIGHT MOUSE BUTTON = Throw, SPACEBAR = Reload"
PRINT "Rotate Character with 'a' and 's' keys"
PRINT "--------------------------------------------------------------------------------------"
SYNC
LOOP
EZrotate! TextureMax! Enhanced Animations! (coming soon....) 3D Character Maker! (coming soon....)