Character Animation Control

Blitz3D Forums/Blitz3D Beginners Area/Character Animation Control

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Seems to be working here, even after doing the jump (and with debug on and "DebugLog currentanimframe" at the start of Update_Character I can see it's going from frame 0 to 40). I'm using the dragon model from "\samples\mak\dragon" BTW.

Here's the full source as I currently have it -- see if it works for you...

AppTitle "Character Animation System", "Are you sure you want to quit?"
Graphics3D 1024,768,16,0
SetBuffer BackBuffer()

;constants
Const FPS = 30

;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$   = "C:\Program Files\Blitz3D\samples\mak\dragon\model\dragon.md2"
Global texturefilepath$ = "C:\Program Files\Blitz3D\samples\mak\dragon\model\dragon.bmp"
Global currentanimframe = 0
Global jumping          = False
Global crouching        = True


;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_Character()

		
		UpdateWorld()
				
	Next
		
	RenderWorld(tween)

	Flip

Until KeyHit(1)

;shutdown program
ClearWorld()
End


;functions
Function Initialise()

	camera=CreateCamera() 
	
	PositionEntity camera,0,3,-4 

	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 ;DEFAULT IDLE ANIMATIION


End Function


Function Update_Character()

	currentanimframe = MD2AnimTime(model)
	DebugLog currentanimframe
	
	Select(True)
				
		Case (KeyHit(57))	: 		AnimateMD2 model, 3, 0.1, 67, 72, 2: jumping  = True ; *****
										
		Case (KeyHit(46))	:		crouching = True 	
									
		Case (KeyDown(200)) :		If (currentanimframe < 40) Or (currentanimframe > 46) AnimateMD2 model, 1,  0.25, 40, 46, 2 ;FORWARD with UP ARROW
				
		Case (KeyDown(208))	:		If (currentanimframe < 40) Or (currentanimframe > 46) AnimateMD2 model, 1, -0.25, 40, 46, 2 ;REVERSE with DOWN ARROW
									
		Default 			:		If (jumping = 0) And (currentanimframe > 40) AnimateMD2 model, 1, 0.05, 0, 40, 2  ; *****	  							  ;DEFAULT IDLE ANIMATIION
									

	End Select
		
	;process animations
;	If (jumping)	 ; *****
					 ; *****
					 ; *****
					 ; *****
;	EndIf			 ; *****
	
	If (currentanimframe => 72) 

		jumping = False
		If (currentanimframe > 40) AnimateMD2 model, 1, 0.05, 0, 40, 2 ;DEFAULT IDLE ANIMATIION
	
	EndIf 

End Function