character animation question

Blitz3D Forums/Blitz3D Beginners Area/character animation question

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.

it's been atleast a couple years since i've used Blitz3D, but this is some code i had lying around on the HD. it should help you out.


;**********************************************************************************
; 
;	B3D Animation Example using ExtractAnimSeq ------------------- Rik Smiff April 2003
;
;
;   Use Keys Q through to  X  to transpose  animation sequences.
;
;	Use the Cursor Keys to Pitch and Yaw the Ninjas Head 
;   - this will blend with the currently running animation
;   
;   You will need the B3D Animated Ninja Model "Ninja.b3d"
;   Kindly  donated by Psionic available on the Blitz forum.
;   or
;   www.psionic3d.co.uk
;   Many Thanks to Psionic for his Model - there arent too many animated B3d's out there to play with


; Extract from Ninja.txt by Psionic - Animation Frames
;
; 1-14	    Walk (normal) 
; 15-30	    Stealth Walk
; 32-44	    Punch And swipe sword
; 45-59	    Swipe And spin sword
; 60-68	    Overhead twohanded downswipe
; 69-72  	Up To block position (play backwards To Lower sword If you want)
; 73-83 	Forward kick
; 84-93	    Pick up from Floor (Or down To crouch at frame 87)
; 94-102	Jump
; 103-111	Jump without height (For programmer controlled jumps)
; 112-125	High jump To Sword Kill (Finish em off move??)
; 126-133	Side Kick
; 134-145	Spinning Sword attack (might wanna speed this up in game)
; 146-158	Backflip
; 159-165	Climb wall
; 166-173	Death 1 - Fall back onto ground
; 174-182	Death 2 - Fall forward onto ground
; 184-205	Idle 1 - Breathe heavily
; 206-250	Idle 2
; 251-300	Idle 3
;**********************************************************************************

Graphics3D 800,600
SetBuffer BackBuffer()
camera=CreateCamera()
MoveEntity camera,0,3,0
CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()
AmbientLight 255,255,255

;********** Load Model  and Prepare Animation Sequences

Global ninja=LoadAnimMesh("ninja.b3d"); This will load All Frames into Sequence 0
Global walk=ExtractAnimSeq (ninja,0,14); Extract frames 0 to 14 into Sequence 1 - the value 1 is assigned to the Global walk
Global stealth=ExtractAnimSeq (ninja,15,30); Extract frames 15 to 30 into Sequence 2 - the value 2 is assigned to the Global stealth
Global punch_swipe=ExtractAnimSeq (ninja,32,44); And so on extracting each set of frames into a seperate sequence 
Global swipe_spin=ExtractAnimSeq (ninja,45,59); and assigning the sequence number to a global variable.
Global overhead=ExtractAnimSeq (ninja,60,68)
Global block=ExtractAnimSeq (ninja,69,72)
Global fwd_kick=ExtractAnimSeq (ninja,73,83)
Global pickup=ExtractAnimSeq (ninja,84,93)
Global jump=ExtractAnimSeq (ninja,94,102)
Global jump_static=ExtractAnimSeq (ninja,103,111)
Global jump_kill_sword=ExtractAnimSeq (ninja,112,125)
Global sidekick=ExtractAnimSeq (ninja,126,133)
Global spin_sword_attack=ExtractAnimSeq (ninja,134,145)
Global backflip=ExtractAnimSeq (ninja,146,158)
Global climb_wall=ExtractAnimSeq (ninja,159,165)
Global death_fall_back=ExtractAnimSeq (ninja,166,173)
Global death_fall_fwd=ExtractAnimSeq (ninja,174,182)
Global idle_breathe_heavy=ExtractAnimSeq (ninja,184,205)
Global idle_2=ExtractAnimSeq (ninja,206,250)
Global idle_3=ExtractAnimSeq (ninja,251,300)
Global crouch=ExtractAnimSeq (ninja,84,87)
;
;locate the head bone in the model and assign it to the Global 'head'
Global head=FindChild(ninja,"Joint7")
 
;Head rotation Variables
Global headyaw,headpitch
Global state
Const transpose = 40
;Position the model 
MoveEntity ninja,0,0,7
ScaleEntity ninja,0.5,0.5,0.5
RotateEntity ninja,0,180,0
;************** Main Loop ***********************************
While Not KeyHit(1)




; Get Cursor Key Input for Manual Head Rotation
If KeyDown(203) Then headyaw=headyaw+1:If headyaw > 90 Then headyaw = 90
If KeyDown(205) Then headyaw=headyaw-1: If headyaw < -90 Then headyaw = -90
If KeyDown(200) Then headpitch=headpitch+1: If headpitch > 30 Then headpitch= 30
If KeyDown(208) Then headpitch=headpitch-1 : If headpitch < -45 Then headpitch= -45


; Get Key Input for Animation sequence change
If KeyDown(16) And latch_key_Q = False Then  Animate ninja,1,0.1,walk,transpose:latch_key_Q = True:state=0
If Not KeyDown(16) Then latch_key_Q = False
If KeyDown(17) And latch_key_W = False Then  Animate ninja,1,0.1,stealth,transpose:latch_key_W = True:state=1
If Not KeyDown(17) Then latch_key_W = False
If KeyDown(18) And latch_key_E = False Then  Animate ninja,3,0.1,punch_swipe,transpose:latch_key_E = True
If Not KeyDown(18) Then latch_key_E = False
If KeyDown(19) And latch_key_R = False Then  Animate ninja,3,0.1,swipe_spin,transpose:latch_key_R = True
If Not KeyDown(19) Then latch_key_R = False
If KeyDown(20) And latch_key_T = False Then  Animate ninja,3,0.1,overhead,transpose:latch_key_T = True
If Not KeyDown(20) Then latch_key_T = False
If KeyDown(21) And latch_key_Y = False Then  Animate ninja,3,0.1,block,transpose:latch_key_Y = True
If Not KeyDown(21) Then latch_key_Y = False
If KeyDown(22) And latch_key_U = False Then  Animate ninja,3,0.1,fwd_kick,transpose:latch_key_U = True
If Not KeyDown(22) Then latch_key_U = False
If KeyDown(23) And latch_key_I = False Then  Animate ninja,3,0.1,pickup,transpose:latch_key_I = True
If Not KeyDown(23) Then latch_key_I = False
If KeyDown(24) And latch_key_O = False Then  Animate ninja,3,0.1,jump,transpose:latch_key_O = True
If Not KeyDown(24) Then latch_key_O = False
If KeyDown(25) And latch_key_P = False Then  Animate ninja,3,0.1,jump_static,transpose:latch_key_P = True
If Not KeyDown(25) Then latch_key_P = False
If KeyDown(30) And latch_key_A = False Then  Animate ninja,3,0.1,jump_kill_sword,transpose:latch_key_A = True
If Not KeyDown(30) Then latch_key_A = False
If KeyDown(31) And latch_key_S = False Then  Animate ninja,3,0.1,sidekick,transpose:latch_key_S = True
If Not KeyDown(31) Then latch_key_S = False
If KeyDown(32) And latch_key_D = False Then  Animate ninja,3,0.1,spin_sword_attack,transpose:latch_key_D = True
If Not KeyDown(32) Then latch_key_D = False
If KeyDown(33) And latch_key_F = False Then  Animate ninja,3,0.1,backflip,transpose:latch_key_F = True
If Not KeyDown(33) Then latch_key_F = False
If KeyDown(34) And latch_key_G = False Then  Animate ninja,1,0.1,climb_wall,transpose:latch_key_G = True
If Not KeyDown(34) Then latch_key_G = False
If KeyDown(35) And latch_key_H = False Then  Animate ninja,3,0.1,death_fall_back,transpose:latch_key_H = True
If Not KeyDown(35) Then latch_key_H = False
If KeyDown(36) And latch_key_J= False Then  Animate ninja,3,0.1,death_fall_fwd,transpose:latch_key_J = True
If Not KeyDown(36) Then latch_key_J = False
If KeyDown(37) And latch_key_K = False Then  Animate ninja,1,0.1,idle_breathe_heavy,transpose:latch_key_C = True
If Not KeyDown(37) Then latch_key_K = False
If KeyDown(38) And latch_key_L = False Then  Animate ninja,1,0.1,idle_2,transpose:latch_key_Z = True
If Not KeyDown(38) Then latch_key_L = False
If KeyDown(45) And latch_key_X = False Then  Animate ninja,1,0.1,idle_3,transpose:latch_key_X = True
If Not KeyDown(45) Then latch_key_X= False
If KeyDown(44) And latch_key_Z = False Then  Animate ninja,3,0.1,crouch,transpose:latch_key_Z = True
If Not KeyDown(44) Then latch_key_Z = False


If Not Animating(ninja) Then 

		If state=0 Animate ninja,1,0.1,walk,40
		If state=1 Animate ninja,1,0.1,stealth,40

End If


UpdateWorld

;Update head rotation
TurnEntity head,headpitch,headyaw,0

RenderWorld
Flip

Wend





i believe this is the model : http://www.psionic3d.co.uk/gallery/displayimage.php?album=2&pos=5

hope this helps.