Model wont animate

Blitz3D Forums/Blitz3D Beginners Area/Model wont animate

YellBellzDotCom(Posted 2006) [#1]
Ok, I have .b3d models of the same mesh, seperate animations. I load the idle mesh using loadanimmesh()
I then load the walk animation using loadanimseq()
I can use the following code...

	If KeyDown(27)
		If AnimSeq(mesh_3ds)=0 Animate mesh_3ds,1,1,1
	Else
		If AnimSeq(mesh_3ds)=1 Animate mesh_3ds,1,.5,0
	EndIf


but if I use an if function to check if the animation is moving and to play the anim sequence for walking if he is moving, the animation wont play. I check the animseq(), animating(), animtime() and animlength() and they all show the correct information onscreen, but it looks like the model is freezing on frame 1.

Heres the code for the walking...
	If MouseHit(1)=True
		SelEnt = CameraPick(cam,MouseX(),MouseY())
		
		If SelEnt > 0
			If EntityName(PickedEntity()) = "Ground"
				Move$ = "True"
				Animate mesh_3ds,1,1,1,trans
			EndIf
		EndIf
	EndIf


Again... thanks in advance!


Bobysait(Posted 2006) [#2]
Maybe try with a latch key


	If KeyDown(27)
		If MeshAn1=False
			Animate mesh_3ds,1,1,1:MeshAn1=True:MeshAn0=False
		EndIf
	Else
		If MeshAn0=False
			Animate mesh_3ds,1,.5,0:MeshAn1=True:MeshAn1=False
		EndIf			
	EndIf


it seems to do the same thing.

For the second code, i use a similar function for click and play game
=>
	If MouseHit(2)
		CameraPick	camera,MouseX(),MouseY()
		Picked=PickedEntity()
		If Picked <> 0
			If Lower(EntityName(Picked)) = "MSH_Sol"
				[...]
			EndIf
		EndIf
	EndIf


Just have to replace .

In any way, unless the animation sequence is not pointed at a good index, it might walk well !


(tu) sinu(Posted 2006) [#3]
This should work


	If MouseHit(1)=True
		SelEnt = CameraPick(cam,MouseX(),MouseY())
		
		If SelEnt > 0
			If EntityName(PickedEntity()) = "Ground"
				Move$ = "True"
				if not animseq(mesh_3ds) =  1
                                   Animate mesh_3ds,1,1,1,trans
                                endif
			EndIf
		EndIf
	EndIf





YellBellzDotCom(Posted 2006) [#4]
Bobysait, theres no reason to change the Keydown(27) code, the code I have works, its just for testing animations in my game. The second block of code, is the actual code used to switch to a walking animation when the model is told to move. I cant understand why my animation works with the keydown(27) code, but it doesnt work in the second block, this is all within the same program.

Sinu, thanks for the attempt but that code didnt change anything, when I click in the game, the model does change to the walking animation for a quick sec, can barely tell it switched, then it goes right back to the idle animation for the duration of the walk.


YellBellzDotCom(Posted 2006) [#5]
Ok, heres a simpler example of whats happening...

I tried using this code to switch the animation from idle to walking...

	If KeyDown(27)
		If AnimSeq(mesh_3ds)=0
			Walk = 1
		EndIf
	Else
		If AnimSeq(mesh_3ds)=1
			Walk = 0
		EndIf
			
	EndIf
	
	If Walk = 1 Then Animate mesh_3ds,1,1,1
	If Walk = 0 Then Animate mesh_3ds,1,.5,0


The model switches to each animation and the animating text shows 1, the animation length text changes to represent the different number of frames for each animation, the animation seq # text changes to show that the correct sequence is actually loaded, but the model is not animating. He just changes to the first frame of each animation and stays there .

It seems the only time the animation actually plays is when I press and hold the right bracket key. Why cant I switch the playing animation using a flag or boolean variable in the main loop so that the animation will play the selected animation until the flag variable is changed? lol.


YellBellzDotCom(Posted 2006) [#6]
dang that was stupid of me...

Ok this code will change the animation and loop it until the bracket key is hit again...
	If KeyHit(27)
		If Walk = 0 
			Animate mesh_3ds,1,1,1
                        Walk = 1
		ElseIf Walk = 1 
			Animate mesh_3ds,1,.5,0
                        Walk = 0
		EndIf
			
	EndIf


This code will also switch the animation, as evidenced in my text output of animlength(), animtime(),animseq(), and animating() (animating shows 1 by the way) but the model is not animating!! lol, I cant grip this!
	If KeyHit(27)
		If Walk = 0 
			Walk = 1
		ElseIf Walk = 1
			Walk = 0
		EndIf
			
	EndIf
	
	If Walk = 1 Then Animate mesh_3ds,1,1,1
	If Walk = 0 Then Animate mesh_3ds,1,.5,0



Matty(Posted 2006) [#7]
You are calling 'updateworld' in your main loop aren't you :

like this:

updateworld
renderworld
flip



Nothing will animate if you don't call updateworld.


YellBellzDotCom(Posted 2006) [#8]
Matty, yes I am, I figured out what was going wrong. I am calling Animate with every flip, so naturally it will only show the first frame of the animation. As Bobysait, kinda pointed out, I need to test if the animation seq is already running, if so, ignore the animation command. Lol, such an obvious booboo.

Thanks for the help!!


Bobysait(Posted 2006) [#9]
I just posted a code to explain what can do a "latch key" . I understood the initial walk. ;)

But, i really think, there is missing something in an other part of your code. Here, noone of the two codes you posted could not work. So it comes from an other part.

Maybe you try using this in a function, and you forget a global var ...

an other way is : maybe you have a "animate" in other part of your code ... don't know, but it's sure => the code should work. It's real as 1+1=2 :)


YellBellzDotCom(Posted 2006) [#10]
lol, No the second block was def incorrect. In the original post, second block of code I was telling the program that if Move$ was true, which it was, Animate the model with the walk animation, which it did, every loop. So it called Animate() every loop, that block of code never gave the animation time to run. Just by putting,
If AnimSeq(mesh_3ds) <> 1 then If Animate mesh_3ds,1,1.5,1


That tells the program, if Animation #1 is not running, run it. If it is running, let it run and leave it alone.

From what I gather, you cant just put,
Animate mesh_3ds,1,1.5,1


in your loop because it will continuously load the animatation and show frame 1 of it every loop.

which you graciously gave an example of in your latch key code, hehehe. Guess I shouldve paid more attention. lol


Bobysait(Posted 2006) [#11]
i know that . Animating models is not a problem for me as i have ever made it thousand of times. But, on your second code, i see the "If Mousehit(1) " ... I don't think mousehit return true every loop. So it animate only one time when you hit mouse button. Don't you think ?

I don't think you are hitting mouse button like a rabbit, or maybe you won't have your mouse clean for long time xD

well, as you've found your problem, that's good. But really, there may be a problem whatever.


jhocking(Posted 2006) [#12]
As he said, it's great that you figured out the problem with your code using the a flag variable, and ultimately that solves your problem by having all your Animate commands centrally located instead of spread throughout your code, but that wasn't the problem with your original code. This comment
Sinu, thanks for the attempt but that code didnt change anything, when I click in the game, the model does change to the walking animation for a quick sec, can barely tell it switched, then it goes right back to the idle animation for the duration of the walk.

makes me suspect that you are calling the idle animation somewhere else in the code, probably if the mouse isn't clicked.


YellBellzDotCom(Posted 2006) [#13]
I apologize for not posting back...

Bobysait, Im sorry I didnt mean to imply anything there, I definitely was not trying to correct you. I didnt have my complete code listed, after 50 trials and errors I moved the Animate function in an if statement that went like this
If Move$ = "True" then Animate mesh_3ds,1,1.5,1

So now my game was testing Move$ every loop which was true and calling animate every loop. Once I changed this and used your flag setting idea, the program worked great. The main fact is, your supreme knowledge of model animating helped me figure out where my error was and I thank you for that. I dont think I was even keeping up with what code I had posted and what problems I had.

jhocking, as youve stated I did set the idle animation before the main loop, then commented it out while trying different things. Basically in the end, I had the animations loaded but didnt call any of them until I clicked the mouse or hit the bracket key, then the model would change to frame 1 of each animation then stay there until I hit the mouse or bracket key again, thats when I found that I improperly set my flag.

Just wanted to say thanks for the help here and everything is going awesome! (Except shadowing, lol)