Changing Animation Speed on the Fly

Blitz3D Forums/Blitz3D Programming/Changing Animation Speed on the Fly

stayne(Posted 2016) [#1]
Hello all. I have a model I'm animating during a keypress and it works fine but I want to change the animation speed according to a animspeed# global that ramps up when the forward key is held down. When I first hold the key down the animation stays at its current speed. If I keep the key down until animspeed# is maxed out, let go and quickly hold it again the model animates at the current speed. It's just not adjusting while holding the key. I've tried SetAnimTime (SetAnimTime mesh,animspeed#,runanim) with the same results.


RemiD(Posted 2016) [#2]
I have done a quick test, and it works as expected here, however the animation speed does not change instantly (increase or decrease) but only for the next sequence.

What are you trying to achieve with that ?

Maybe you could stop the current animation and get the current frame, and have ready to use animations from framen to framend and play the appropriate animation from the current frame to the end frame with the animspeed that you want... (if your animations are made with only a few poseframes and many emptyframes, this should not use much memory...) (not tested but worth a try)


RemiD(Posted 2016) [#3]
I have done some tests by curiosity, and here is a way to force the restart of the animation with a different speed if the set animspeed is different this mainloop than it was during the previous mainloop.
;before the mainloop :
Global AnimSpeed# = 1.0
Global PrevAnimSpeed# = AnimSpeed

;in the mainloop :
 ;to increase/decrease the animspeed
 If( KeyDown(44)=1 )
  AnimSpeed = AnimSpeed - 0.1
  If( AnimSpeed < 0.1 )
   AnimSpeed = 0.1
  EndIf
 Else If( KeyDown(45)=1 )
  AnimSpeed = AnimSpeed + 0.1
  If( AnimSpeed > 2.0 )
   AnimSpeed = 2.0
  EndIf
 EndIf
  
 ;to animate
 If( KeyDown(57)=1 ) 
  If( AnimSeq(TestSkeleton) <> TestAnimation ) Or ( AnimSeq(TestSkeleton) = TestAnimation And Animating(TestSkeleton) = False ) Or ( AnimSeq(TestSkeleton) = TestAnimation And AnimSpeed <> PrevAnimSpeed ) 
   Animate(TestSkeleton,3,AnimSpeed,TestAnimation)
   PrevAnimSpeed = AnimSpeed
  EndIf
 EndIf
 UpdateWorld()



stayne(Posted 2016) [#4]
Thanks RemiD. It's a humanoid running animation so I am trying to figure out how to speed up the animation according to run speed which speeds up from 0 to 1.6 while the run key is held down.


RemiD(Posted 2016) [#5]
In this case, i suggest to have 2 running animations, one for each with a leg (right or left) forward.
Then when you want to increase the animation speed, determine what is the current frame, then depending on the leg forward (right or left), start to play the appropriate new animation with the new speed.
The change will probably not be noticeable...


An alternative would be to have an animation with many emptyframes between poseframes and use SetAnimTime() to animate it (go to the next frame with the speed that you want)


Kryzon(Posted 2016) [#6]
I know what you're asking for, but it can't be done with Blitz3D. The animation system is just too simple.
You don't have control over any nodes (create, modify or delete bones, sequences etc.).

One way to [visually] do what you want is to have different animation sequences for different ranges of speed, then play (with a large transition period, like '10' or more) a different sequence when the speed enters a different range.

Kinda like the blending of the 'walk' and 'run' sequences in this:
http://threejs.org/examples/#webgl_animation_skinning_blending