animation only while keydown...
Blitz3D Forums/Blitz3D Programming/animation only while keydown...
| ||
I have Been struggling with blitz3d's animation commands for a long time. My game's main character should only play an animation sequence when holding the key down. Can somebody skilled in animation on Blitz3d give me Some Advice please? Thank you! :) I am on mobile so dont have good typing skills with thi virtual keyboard. Sorry. You can Download last Year preview version 0f my application at Captainwicker.com homepage. |
| ||
To start, you could try something like this:If Keydown(N) If Not Animating(ent) Then Animate ent, 1, ... Else If Animating(ent) Then Animate ent, 0 EndIf This method will just start the animation again when the key is next pressed, instead of resuming it wherever it left off: to do that, you'd need to build a semi-custom animation management system using SetAnimTime. (I'm terrible with animations, my skill ends here.) |
| ||
Thanks Yasha. I have Been using this method, but I have problems switching to other animations. Sorry I didn't mention that in my first post. |
| ||
Why doesn't the object animate while it is moving? It is using bone animation, I think.If Not Debug=1 Set3rdPersonEnt(cam,cube,10,10) If KeyDown(200) MoveEntity cube,0,0,.25 If Not Animating(cube) Then Animate cube, 1,.1,walk If Animating(cube) Then Animate cube, 1,.1,walk EndIf EndIf |
| ||
As far as I can see, you are starting the animation if it is not animating AND again if it is animating! At a guess, the effect you are seeing is a stuttering of the start of the animation while the key is held down. You are missing the Else part from Yasha's example. Maybe putting in the Else condition will help. |
| ||
If KeyDown(200) MoveEntity cube,0,0,.25 Animate cube, 1,.1,walk Else Animate cube, 1,.1,idle EndIf |
| ||
@_PJ_: Ok, that too will just produce the stutter effect. Try it this way: If Not Debug=1 Set3rdPersonEnt(cam,cube,10,10) If KeyDown(200) MoveEntity cube,0,0,.25 If Not Animating(cube) Then Animate cube, 1,.1,walk Else If Animating(cube) Then Animate cube, 0 EndIf EndIf Change Animate cube, 0 to whatever you have for stopped state. This sort of thing is not really about knowing how to animate, it's about knowing applied logic. It's a requirement to understand logic rules as a coder no matter which language you are using :) |
| ||
Don't mind me asking but what is the difference between else and elseif having to do with my problem? My blitz3d has gotten a little rusty as I haven't really used it since last December + my short term memory loss makes me forget a lot of things. Sorry. |
| ||
Your Complex Character™: lots of sequences (idle, running, attack, death1, death2 etc.). How to manage them: 1) Figure the current state the character is in. 2) Update his animation based on that state. ;Section 1 (figure the best current state): kUp = KeyDown(200) kDown = KeyDown(208) If kUP=1 And kDown=0 Then currentState = STATE_MOVE_FORWARD If kUp=0 And kDown=1 Then currentState = STATE_MOVE_BACKWARD If (kUp+kDown)<>1 Then currentState = STATE_IDLE ;Section 2 (update movements, anims, settings based on state): Select currentState Case STATE_MOVE_FORWARD MoveEntity cube,0,0,.25 ;Forward If AnimSeq(cube)<>ANIM_SEQ_FORWARD Then Animate cube,1,.1,ANIM_SEQ_FORWARD Case STATE_MOVE_BACKWARD MoveEntity cube,0,0,-.25 ;Back If AnimSeq(cube)<>ANIM_SEQ_BACKWARD Then Animate cube,1,.1,ANIM_SEQ_BACKWARD Case STATE_IDLE If AnimSeq(cube)<>ANIM_SEQ_IDLE Then Animate cube,1,.1,ANIM_SEQ_IDLE End SelectClean. |
| ||
Kyyzon: But the character is now moving forward regardless of whether I am pressing the up key.? |
| ||
It only moves when you call MoveEntity. If you read your code very carefully you'll find that you're not putting your character into an idle state where it stays still, with no mention of MoveEntity being made. |
| ||
I think I have a decent suggestion. this is more of a way to separate the movement and animation arguments from the keydown arguments to help organize it all. I would have an integer be responsible for which animation your character is ordered to do when it is at a certain value, then have your animation and movement commands be inside a select case argument so that when you have the keydown, in another function to keep everything in its own step, then when you hold the key down the keydown argument keeps the value as it is or if the key is not down then that integer will return to a basic value for idle animation, you could build in an effect for a transition animation as the value could decrease by 1 every frame until it reaches zero, then during that transition period the animation your character goes through is both speed reduction as the animation slows down based on the integer. example: if keydown() forward=10 else if forward>0 forward=forward-1 endif endif ;;;;I prefer an if statement. If forward>0 ;;your animation commands and somehow link that forward integer to the anim speed. elseif forward=0 ;; tell it to idle animate, or if already idle animating, then to continue. endif ;; once it reaches zero, if the character isn't going any other direction, have an idle animation or a couple that the character loops through. I don't know if this helps but if you have this argument then your character should always be animated whether it is the forward moving anim or the idle anim it defaults to. |