Question "Spool up" an animation

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
179
Reaction score
116
Points
43
Location
Southwest Pennsylginia
Website
sites.google.com
Is it possible to spool up a rotation animation?
That is, start from 0 rpm and increase rpm over a period of so many seconds.
If not with an animation can it be done with "set_angvel" ?
 
Depends - do you mean in C++ or in Lua? Then yes, there are ways.
 
Then, its your choice, how you want to do it... first, you should treat the speed of the animation as a variable. Then, you should choose how you want the behaviour to be. You could define a mathematical function that mimics the behaviour you want in the style of:

animation_speed = animation_speed + any_function(animation_speed) * delta_simt.

The simplest example of such a function would just be the classic arithmetic average function.

any_function = (animation_speed + target_speed) / 2

You could also use a state machine. Lets say, you have four states: Off, spool up, run, spool down. For starting the animation, you go from off state to spool up. In spool up, you just increase the animation_speed until it has reached your reference speed. When the reference speed is exceeded, the state switches to run. When you want to turn the animation off, you leave run towards the state spool down and decrease your animation speed until its zero or less. Then it sets the animation speed to zero and goes to off state again.
 
Then, its your choice, how you want to do it... first, you should treat the speed of the animation as a variable. Then, you should choose how you want the behaviour to be. You could define a mathematical function that mimics the behaviour you want in the style of:

animation_speed = animation_speed + any_function(animation_speed) * delta_simt.

The simplest example of such a function would just be the classic arithmetic average function.

any_function = (animation_speed + target_speed) / 2

You could also use a state machine. Lets say, you have four states: Off, spool up, run, spool down. For starting the animation, you go from off state to spool up. In spool up, you just increase the animation_speed until it has reached your reference speed. When the reference speed is exceeded, the state switches to run. When you want to turn the animation off, you leave run towards the state spool down and decrease your animation speed until its zero or less. Then it sets the animation speed to zero and goes to off state again.
This is more or less what I did in my helicopter code, though I don't use the simulation time step. The main throttle input specifies the target_speed of the rotor, and the rotor speed is set by something like:

Code:
animation_speed = animation_speed + constant * (target_speed - animation_speed)

This allows a spool up as well as a spool down when throttle is reduced. The constant is user specified between 0 to 1 to adjust the rate of spool up or down.

It's not particularly sophisticated but it mimics the lag pretty well. There is no accounting for frame rate so you can get some visual aliasing due to frame rate depending on the animation_speed.
 
I'm making a satellite that spins up to a certain rpm and stays there.
I got it working using a timer with a limit.

Code:
if spin_timer == nil then
  spin_timer = 0
end

local tm = oapi.get_simstep()
spin_timer = spin_timer + tm

  --  time limit for increasing rpm
if spin_timer >= 10 then
  spin_timer = 10
end

if sat1_spin == nil then
  sat1_spin = 0
end

  --  how fast rpm increases
sat1_spin = (sat1_spin + (spin_timer*(tm/6.75))) % 1

vi:set_animation (anim_Sat1, sat1_spin)

it works but the start of the spin is a bit abrupt.
Thanks all for the help. (y)
 
Last edited:
Back
Top