Thanks!
Still having a problem with the Death animation sequence.
It plays out normally, then tweens back to an earlier frame.
Any ideas?
The model file and texture can be downloaded from here:
http://www.octanedigitalstudios.com/downloads/AnimationControl.zipHere's my latest code:
AppTitle "Character Animation System", "Are you sure you want to quit?"
Graphics3D 800,600,16,0
SetBuffer BackBuffer()
Include "keyconstants.bb"
;constants
Const FPS = 30
Const type_MD2 = 1000
Const type_B3D = 1001
Const type_3DS = 1002
;globals
Global index% = 0
Global ticks# = 0.0
Global elapsed# = 0.0
Global period# = 1000/FPS
Global time# = MilliSecs() - period
Global tween# = 0.0
Global model = 0
Global texture = 0
Global camera = 0
Global light = 0
Global modelfilepath$ = "tris.md2"
Global texturefilepath$ = "alita.pcx"
Global g_currentanimframe = 0
Global g_jumping = False
Global g_dying = False
Global g_character_is_dead = False
;start program
Initialise()
;main loop
Repeat
Repeat
elapsed = MilliSecs() - time
Until elapsed
ticks = elapsed / period
tween# = Float(elapsed Mod period)/ Float(period)
For index = 1 To ticks
time = time + period
If (index = ticks) CaptureWorld()
Update_CharacterAnimation(model, type_MD2)
UpdateWorld()
Next
RenderWorld(tween)
Color 0,0,255: Text 5, 2, "Animation Frame: " + g_currentanimframe
Color 255,255,255
Text 5, 20, "ARROW KEYS = FORWARDS \ BACK"
Text 5, 35, "SPACE = JUMP"
Text 5, 50, "C KEY + ARROW UP = CROUCH WALK"
Text 5, 65, "D KEY = DEATH"
If (g_character_is_dead=True)
Color 255,0,0:Text 5, 80, "Character is dead!"
EndIf
Flip
Until KeyHit(1)
;shutdown program
ClearWorld()
End
;functions
Function Initialise()
camera=CreateCamera()
PositionEntity camera,0,3,-5
light=CreateLight()
PositionEntity light, 2, 6, -5
model = LoadMD2(modelfilepath)
texture = LoadTexture(texturefilepath)
ScaleEntity model, 0.07, 0.07, 0.07
EntityTexture model, texture
PositionEntity model, 0, 1.7, 0
PointEntity camera, model
PointEntity light, model
EntityParent light, model
AnimateMD2 model, 1, 0.1, 0, 40, 4 ;DEFAULT IDLE ANIMATIION
End Function
Function Update_CharacterAnimation(v_model, v_model_type)
g_currentanimframe = process_anim_frame(v_model, v_model_type);Get the current animation frame
If (g_character_is_dead=False)
Select(True)
Case (KeyHit(KEY_D)) : process_dying(v_model, v_model_type) ; DEATH 1 with D
Case (KeyHit(KEY_SPACE)) : process_jump(v_model, v_model_type) ; JUMP with SPACE BAR
Case (KeyDown(KEY_C)) : process_crouching(v_model, v_model_type) ; CROUCH IDLE and CROUCH WALK with C key and/or ARROW KEYS
Case (KeyDown(KEY_ARROWPAD_UP)) : process_run(v_model, v_model_type) ; RUN with UP ARROW
Case (KeyDown(KEY_ARROWPAD_DOWN)) : process_run_backwards(v_model, v_model_type); RUN BACKWARDS with DOWN ARROW
Default : If (g_dying=True)
process_dying(v_model, v_model_type) ; CHARACTER IS DYING
Else
process_idle(v_model, v_model_type) ; DEFAULT IDLE ANIMATIION
EndIf
End Select
If (g_currentanimframe = 72)
g_jumping = False
If (g_currentanimframe > 40) AnimateMD2 v_model, 1, 0.1, 0, 40, 4 ;DEFAULT IDLE ANIMATIION
EndIf
If (g_currentanimframe = 184)
g_character_is_dead = True
EndIf
Else
;Character is dead - perform post mortem processes here
EndIf
End Function
Function process_anim_frame%(v_model, v_model_type)
If (v_model_type = type_MD2)
Return MD2AnimTime(v_model)
Else
Return AnimTime(v_model)
EndIf
End Function
Function process_idle(v_model, v_model_type)
If (Not g_jumping) And (Not g_death) And (g_currentanimframe > 40)
AnimateMD2 v_model, 1, 0.1, 0, 40, 4 ; DEFAULT IDLE ANIMATIION
EndIf
End Function
Function process_jump(v_model, v_model_type)
If (v_model_type = type_MD2)
AnimateMD2 v_model, 3, 0.1, 67, 72, 4
g_jumping = True
Else
;animate other model types here
EndIf
End Function
Function process_run(v_model, v_model_type)
If (KeyDown(KEY_C)=False)
If (v_model_type = type_MD2)
If (g_currentanimframe < 41) Or (g_currentanimframe > 46)
AnimateMD2 v_model, 1, 0.25, 41, 46, 4
g_jumping = False
EndIf
Else
;animate other model types here
EndIf
EndIf
End Function
Function process_run_backwards(v_model, v_model_type)
If (KeyDown(KEY_C)=False)
If (v_model_type = type_MD2)
If (g_currentanimframe < 41) Or (g_currentanimframe > 46)
AnimateMD2 v_model, 1, -0.25, 41, 46, 4
g_jumping = False
EndIf
Else
;animate other model types here
EndIf
EndIf
End Function
Function process_crouching(v_model, v_model_type)
Select(True)
Case (KeyDown(KEY_ARROWPAD_UP)=True) : If (v_model_type = type_MD2);CROUCH WALK FORWARDS - UP ARROW
If (g_currentanimframe < 155) Or (g_currentanimframe > 160)
AnimateMD2 v_model, 1, 0.1, 155, 160, 4
g_jumping = False
EndIf
Else
;animate other model types here
EndIf
Case (KeyDown(KEY_ARROWPAD_DOWN)=True) : If (v_model_type = type_MD2);CROUCH WALK BACKWARDS - DOWN ARROW
If (g_currentanimframe < 155) Or (g_currentanimframe > 160)
AnimateMD2 v_model, 1, -0.1, 155, 160, 4
g_jumping = False
EndIf
Else
;animate other model types here
EndIf
Default : If (v_model_type = type_MD2);CROUCH IDLE
If (g_currentanimframe < 136) Or (g_currentanimframe > 154)
AnimateMD2 v_model, 1, 0.1, 136, 154, 4
g_jumping = False
EndIf
Else
;animate other model types here
EndIf
End Select
End Function
Function process_dying(v_model, v_model_type)
If (v_model_type = type_MD2)
If (g_currentanimframe < 179) Or (g_currentanimframe > 184)
AnimateMD2 v_model, 3, 0.1, 179, 184, 1
EndIf
g_jumping = False
g_dying = True
Else
;animate other model types here
EndIf
End Function
Rogue Vector.