Pressing Buttons to Animate

Blitz3D Forums/Blitz3D Beginners Area/Pressing Buttons to Animate

En929(Posted April) [#1]
I was having trouble with my animation. I wanted to make it so that when the left or right key is pressed, the walking animation starts (as in a normal game) and when it is not pressed, the animation stops. How do I do that with my code below? Thanks!





Graphics3D 800,600 

SetBuffer BackBuffer() 

camera=CreateCamera() 
CameraViewport camera,0,0,800,600 

light=CreateLight() 

man= LoadAnimMesh ("Marty.b3d" ) 
PositionEntity man,0,-330,600 
ScaleEntity man, 3, 3, 3
RotateEntity man,0,0,0 




While Not KeyHit(1) 



	If KeyDown(203) Then 
	
		MoveEntity man, -3,0,0 

		 Animate man,1,0.5,0
	

		
	
	End If 
	
	If KeyDown(205) Then 
	
		MoveEntity man, 3,0,0 
	
		Animate man,1,0.5,0

		
	
	End If 
	


	
	
UpdateWorld 
RenderWorld 

Text 320,500,"An Animated MD2 Demo" 

Flip 

Wend 
End 



skidracer(Posted April) [#2]
untested but I think this logic should work:

	If KeyDown(203) Then 
		MoveEntity man, -3,0,0 
		 Animate man,1,0.5,0
	ElseIf KeyDown(205) Then 	
		MoveEntity man, 3,0,0 
		Animate man,1,0.5,0		
	Else
		Animate man,0
	End If 



En929(Posted April) [#3]
Skidracer, I copied and pasted the code that you sent, but it's not working correctly.


RemiD(Posted April) [#4]
here is an extract from a code i worked on a few months ago (all worked well) :



Flanker(Posted April) [#5]
The code posted by skidracer should work for B3D model.

At the bottom of your code you wrote "An Animated MD2 Demo", if your model is an MD2 you'll have to use the command AnimateMD2, wich is a little different.


En929(Posted April) [#6]
Ok, I got my animation ALMOST to where I want it. Thanks for the info Skyricer, I got it to work. And Flanker, lol, the "An Animated MD2 Demo" was something that I forgot to take out. I copied and pasted some of this code. Remi, thanks for the help. I'm kind of a newbie to programming in Blitz 3D, thus I was trying to learn more about what you wrote in maybe small steps. But, what do you think about my code below?

I got my walking animation to work (after a lot of wrestling with the codes) and the walking animation works with all the buttons that I wanted. That is, when I press the arrow keys, my character walks.

But, now I'm wondering why isn't my punch animation playing through? When I hit the "A" key, it only plays the first animation frame, but stops there. Thus, what should I add to my code to get it to play the full animation when the A key is pressed. Here's the code that I came up with.

By the way, I put both my walk animation and punch animation all on the same strip.

Thanks



Graphics3D 800,600 

SetBuffer BackBuffer() 

camera=CreateCamera() 
CameraViewport camera,0,0,800,600 

light=CreateLight() 



man = LoadAnimMesh ("Henry2.b3d") 
ScaleEntity man, 3, 3, 3
RotateEntity man,0,0,0 
PositionEntity  man, frames -0,-330,600 

walking = ExtractAnimSeq(man, 3,30)


;This is the punch animation that I added.
;The beginning of this clip starts at frame 49
;on the filmstrip.
punching = ExtractAnimSeq(man, 49,99)




While Not KeyHit(1) 


If KeyDown(200) Or KeyDown(208) Or KeyDown(203) Or KeyDown(205) Then

	



Else 
	 
		Animate man, 1,0.5, walking 


EndIf 




If KeyDown(30) Then

;this is the part that I needed help with specifically. The punch animation
;only plays the first frame when I press the A key. But, I want to play the full animation here.

Animate man, 1, 1, punching






Else 




EndIf 






;----------------------Everything below this line is fine for now. Thanks!------------------------------------------------------


If KeyDown(200) MoveEntity man,  0,3,0 
If KeyDown(205) MoveEntity man,  3,0,0 
If KeyDown(208) MoveEntity man,  0,-3,0 
If KeyDown(203) MoveEntity man, -3,0,0 


		
UpdateWorld 
RenderWorld 



Flip 

Wend 
End 




Midimaster(Posted April) [#7]
An punching animation should start on Keydown() like the walking animation. But then it should run independent from the Key status. So try this:

PunchIsRunning knows three status: 0="No Punch", 1="Start Punch" and 2="Punch already running"

Global PunchIsRunning=0
Const ONE_SHOT=3 
....
If PunchIsRunning=1 ;animation starts
     Animate man, ONE_SHOT, 1, punching
     PunchIsRunning=2
ElseIf PunchIsRunning=2 ; animation already running
     If AnimationTime=99
          PunchIsRunning=0 ;reset,when ready     
     Endif
ElseIf KeyDown(30) Then
     PunchIsRunning=1
EndIf