change animation speed

is it possible to change the speed of an animation in game?

like, the faster my character runs the faster will the animation play.

Ty in advance! :smiley:

you shoud use python for that

from bge import logic

cont = logic.getCurrentController()
own = cont.owner

start = 0 (start frame)
stop = 100 (stop frame)
anispeed = 1 (default animation speed, the more higher it is, the faster the animation will play)
aniblend = 5 (blending frames)

own.playAction (“animationname”, start ,stop , play_mode=1, blendin=aniblend, speed=anispeed)

Or you can use the property driven action actuator.
animation_speed.blend (402 KB)

In this example the cube moves as the property changes. If you set it to add +2 instead of +1 it will move at double speed. If you make the animation really long you can set the speed like +100 or + 150 per tic to get finer control.

wow i did not know that would work

The only downside to property driven animations is that they don’t blend well. So you have to find the right situation to use them in.
As an alternative you can use the python animation code to set speed but you’ll need to do something like we dis before, only activate the code when the speed changes, at that time grab the current frame and play from there with the new speed.