A Slider Controlling the Speed of an Animation and Adding a Second Slider - Blend4web Scripting

Опубликовано: 27 Май 2026
на канале: AI generated free movies and games
1,930
15

This tutorial shows how to use a slider to control the play speed of an animated object in a 3D scene. This tutorial also shows how to add a second slider to an application.

The example used in the tutorial is a slider controlling the speed the moon orbits the earth and a second slider to control the spin speed of the earth.

This tutorial follows on from the previous tutorial that showed how to link a range slider to the Z location of an object.

The Blend4web API animation module has a function that will set the speed of an object’s animation. The module allows animation actions to be applied to objects. The set_speed function sets a multiplying factor that is applied when the action is played. Positive values greater than one increase the play speed, positive values less than one decrease the play speed. Negative values reverse the play direction.

This tutorial shows how to link the value of a slider to the play speed of actions applied to objects. The slider minimum value is set to zero but this creates a problem because you cannot stop an animation by setting the speed to zero.

The simplest solution is not to set the minimum value to zero, setting it to one will slow the animation down without stopping it.

If you want to be able to stop the animation then you have to use the stop function. An if statement is used to detect when the slider value becomes zero and the stop function is called.

This creates a problem the next time the slider is moved, because the animation has been stopped. Additional code is needed to play the animation if the value of the slider is not zero and the animation is stopped.

The tutorial shows how to add a second slider, to control the spin speed of the earth. The second slider is made by copying and pasting the code for the first slider and editing the copied code.

The files used in the tutorial can be downloaded from my website -
http://blender.freemovies.co.uk/slide...

Download blend4web from -
https://www.blend4web.com/en/