If [enter action here] then animate mesh

Blitz3D Forums/Blitz3D Beginners Area/If [enter action here] then animate mesh

AvestheFox(Posted 2010) [#1]
I'm not at all new to Blitz3D, but I am somewhat new to using the animate command.

I've played with this command on and off over the years but never really used it with any of my projects. I know how to extract animation sequences from an animated mesh and I know how to call them into play using

animate mesh,1,.5,anim_seq

but my problem is that I want to animate things while a certain action (or event) is playing... Like say while the up key is being pressed, I want to play the walking animation. or while the player mesh is in the air and not colliding with the ground, I want the falling animation to play (or the jumping animation, if a jump action is taking place)

But it seems that when using the animate command it animates when something calls it into action and it doesn't stop until some other command tells it to do so...

Its a bit hard to explain... but I'd like to use my code like this:

if keydown(200) then
animate player,1,.5,anim_run
else
animate player,1,.5,anim_stand
end if

But it doesn't seem to be as simple as that... It seems I would have to set up some kind of complex flag system for when the up button is being pressed, and if the up button is released to switch the animation sequence from running to standing (or other)

But there's got to be a more simpler way to doing this...

Am I right?


stanrol(Posted 2010) [#2]
you could be right, it's beyond me.


AvestheFox(Posted 2010) [#3]
that reply was very insightful and helpful. Thanks :P


Matty(Posted 2010) [#4]
There are many ways of doing this.
However,
By keeping the current animation sequence id stored in a flag, and using the Animating command to check if the entity is currently animating it makes things much easier.

Note it's been a long time since I've used blitz3d but what I used to do was something along the lines of this:

;pseudo code

;in your loop

if keydown(walk key) then 
     moving=true
     if my current sequence is not walking then set the animation sequence to walk mode - looped
     elseif my current sequence is walking then do nothing..as it is already looped
else 
     moving=false
     if my current sequence is idle then do nothing as it is already looping
     if my current sequence is not idle then set it to idle, and looped
endif





GIB3D(Posted 2010) [#5]
You are constantly calling the Animate command which resets the animation. What you need to do is call it once when you want to start it. I'm sure you can figure out a system to do that.


AvestheFox(Posted 2010) [#6]
so pretty much this works:

If KeyDown(200) Then 
	If AnimSeq(mesh)<>anim_walk Then Animate mesh,1,1,anim_walk
Else 
	If AnimSeq(mesh)<>anim_stop Then Animate mesh,1,.2,anim_stop
EndIf


thanks! :)


RGF(Posted 2010) [#7]
Just check if current animseq matches desired action

; seq 1 walk
; seq 2 idle
; seq 3 run
; seq 4 jump

If unit\isidle=False
If isjumping=True
If AnimSeq(unit\mesh)<>4 Then Animate unit\mesh,1,2,4,0
EndIf

If running=True
If AnimSeq(unit\mesh)<>3 Then Animate unit\mesh,1,1.4,3,0
EndIf

If running=False
If AnimSeq(unit\mesh)<>1 Then Animate unit\mesh,1,1.4,1,0
EndIf
EndIf

If unit\isidle=True
If AnimSeq(unit\mesh)<>2 Then Animate unit\mesh,2,.4,2,4
EndIf


Kryzon(Posted 2010) [#8]
save those calls by retrieving the value into a variable:
currentAnim = AnimSeq(Unit\mesh)

If Not unit\isIdle and isJumping Then
      If currentAnim <> 4 Then [...]
Endif

[...]



RGF(Posted 2010) [#9]
Anyway, you would have to check the value of animseq() or "currentanim" in each loop, before animating...


Drak(Posted 2010) [#10]
Use the Animating() command. It tells you if the mesh is animating or not.

As is:
If KeyDown(200) 
	If Animating(player) = False
		Animate player,1,.5,anim_run 
	End If
Else 
	If Animating(player) = False
		Animate player,1,.5,anim_stand
	End If 
End If