Question animation duration in Lua vessel [solved]

johnnymanly

Member
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Hello, I'm animating the landing gear in a Lua vessel like this:

Code:
function clbk_poststep(simt,simdt,mjd)

  alt = vi:get_altitude()
  lgr = vi:get_animation(anim1)

  if lgr == 1 and alt > 250
   then
    vi:set_animation(anim1,0)
  end
  if lgr == 0 and alt < 200
   then
    vi:set_animation(anim1,1)
  end

end

This works but it's instant. I need to set the duration of the animation but I can't figure it out.:unsure:
any ideas?
Thanks.
 

diogom

Well-known member
Joined
Aug 2, 2010
Messages
1,370
Reaction score
413
Points
98
I'm not familiar with Lua, but it seems the method from C++ should still apply: usually, you define the animation progress as a variable, say lgr_proc, which is at 0 or 1 when static, as you do. But then when the animation is triggered (in your case, at the threshold altitudes), you gradually increment (or decrement) this variable, and use it to set the animation. Something like:

da = simdt * scale_factor
lgr_proc = lgr_proc +- da
vi:set_animation(anim1, lgr_proc)

So for every timestep lgr_proc increases (or decreases), and you check for when it goes above 1 (or below 0), that's when the animation ends and you force the 1 or 0 value. By using the simulation timestep (simdt), you can give the animation a fixed duration regardless of frame rate, and with the scale_factor and some experimenting, you can control how long it will take (values between 0 and 1 should increase the duration, and > 1 will shorten it). The API_Guide in Orbitersdk/Doc (page 23), despite not being Lua, could help illustrate how to do this.

You would also need more than two states for the animation. For example, if it's a landing gear, you'd need Retracted, Deploying, Deployed, Retracting.
 

johnnymanly

Member
Joined
Mar 17, 2008
Messages
55
Reaction score
23
Points
8
Location
Southwest Pennsylginia
Thanks again.
This is working code though it seems peculiar.

Code:
function clbk_poststep(simt,simdt,mjd)

  alt = vi:get_altitude()
  lgr = vi:get_animation(anim1)

  da = simdt * 1
  lgr_proc1 = lgr - da
  lgr_proc2 = lgr + da

  if lgr > 0 and alt > 250
   then
    vi:set_animation(anim1,lgr_proc1)
  end
  if lgr < 1 and alt < 200
   then
    vi:set_animation(anim1,lgr_proc2)
  end

end
 
Top