Animating Md2 style B3Ds

Blitz3D Forums/Blitz3D Programming/Animating Md2 style B3Ds

Oiduts Studios(Posted 2009) [#1]
I could not find anything on this in the forums so i'm sorry if this has already been answered. Anyway, i have some B3Ds i downloaded from Psionic, right now i am working with the zombie model. These models have all of the animations in one file. I am unfamiliar to this except for Md2s. I am having problems with animating them. When i press enter it just transitions to the animation but it doesn't animate.

This is the link for the model...
http://www.psionic3d.co.uk/wp-content/uploads/2009/07/zombie.zip

Heres my code.

Graphics3D 800,600,32,2

mesh=LoadAnimMesh( "zombie.b3d" )
p1=ExtractAnimSeq(mesh,2,20 )
p2=ExtractAnimSeq(mesh,137,169 )

pivot=CreatePivot()
cam=CreateCamera( pivot )
PositionEntity cam,0,10,-15

lit=CreateLight()
RotateEntity lit,45,45,0

;Animate mesh_x,1,.5,p2,10

While Not KeyHit(1)
	
	
	If KeyDown(28)
		Animate mesh,1,.5,p1,10
	Else
		Animate mesh,1,.5,p2,10
	EndIf
					
	UpdateWorld
	RenderWorld
	Flip	
Wend
End



Matty(Posted 2009) [#2]
Need to use the animatemd2 commands

edit - scrub that I thought you wanted to animate an md2


Matty(Posted 2009) [#3]
Think for a minute - for every frame that you are not pressing keydown(28) it will set the animation frame to the start of the p2 sequence. Once you press keydown(28) it will go to the start of p1 sequence, but then immediately go back to the start of p2 sequence once you let go of the key.

You do not need to keep calling the animate command each frame, simply call the animate command when the state changes, but let it go after that.


Oiduts Studios(Posted 2009) [#4]
ok... so i did this, i am very tired so logic thinking is kind of hard.
But how would i do the second animation when i am not holding down the key. (p2 is idle and p1 is running.)

If Not KeyDown(28)
Animate mesh,1,.5,p1,10
;Else
; Animate mesh,1,.5,p2,10
EndIf


Matty(Posted 2009) [#5]
;codesnippet
CurrentAnimMode=p1
While (Not (Keyhit(1)))

	If KeyDown(28) and CurrentAnimMode=p2
		CurrentAnimMode=p1
		Animate mesh,1,.5,p1,10
	Endif
	If CurrentAnimMode=p1 And KeyDown(28) = 0	
		CurrentAnimMode = p2
		Animate mesh,1,.5,p2,10
	Endif
;something along those lines.



Oiduts Studios(Posted 2009) [#6]
Wow thanks i get it now and by the way your code works perfectly, thanks again for your time.


Oiduts Studios(Posted 2009) [#7]
I have ran into another problem, when i implant the code into the full code the object will not animate at all, even if i put one animate command after i load the object, i have tried everything i think. Are there any commands that stop animations? All my ingame Md2s are working just fine.


Matty(Posted 2009) [#8]
you need to call 'updateworld' once per frame at least. Maybe you've forgotten to call that function?


Oiduts Studios(Posted 2009) [#9]
that doesnt seem to be the problem. By the way the base code for the game started as the castle demo. Here is the function that is called before renderworld, updategame, updateworld, and other update functions...(once per loop)




Matty(Posted 2009) [#10]
CurrentAnimMode - always equals zero as it is a local variable and not defined when you enter the function call.

You may need to rethink the way you design your program flow and data types otherwise it is just going to get messier and messier.


Oiduts Studios(Posted 2009) [#11]
ya i set it as global variable


Matty(Posted 2009) [#12]
Did you initialise it to be set to p1 or p2 to start with?


Oiduts Studios(Posted 2009) [#13]
i have tried both


Oiduts Studios(Posted 2009) [#14]
i just threw in the same model in the same program with the same code and everything and it works, but the player model does not. Have you looked at the castle demo code, it copies player_model and turns it into p\model with the parent being p\entity, does all of this stuff halt animation in b3ds?
by the way i have already tried .x, .3ds, and .md2 and all of those work but my .b3d's do not work.