Problem Misbehaving animation

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
179
Reaction score
116
Points
43
Location
Southwest Pennsylginia
Website
sites.google.com
I have rotation animations on the third stage and payload of a multistage vehicle.
Everything's fine until the jettisoned payload starts to rotate. It stutters for a second, rotates the wrong way for a few seconds, then changes direction and works normally.
Maybe an animation expert can help me out.
I hope this makes sense.:unsure:
Code:
trans_Third = {                     -- transformation for third stage animation
    type = "rotation",              -- transformation type
    mesh = 0,                       -- mesh index
    grp = 0,                        -- groups
    ref = {x=0,y=0,z=0},            -- reference point
    axis = {x=0,y=0,z=-1},          -- rotation axis
    angle = 360*RAD                 -- rotation angle
}

trans_Sat1 = {                      -- transformation for satellite animation
    type = "rotation",              -- transformation type
    mesh = 0,                       -- mesh index
    grp = 1,                        -- groups
    ref = {x=0,y=0,z=0},            -- reference point
    axis = {x=0,y=0,z=-1},          -- rotation axis
    angle = 360*RAD                 -- rotation angle
}

trans_Sat2 = {                      -- transformation for jettisoned satellite animation
    type = "rotation",              -- transformation type
    mesh = 0,                       -- mesh index
    grp = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},   -- groups
    ref = {x=0,y=0,z=0},            -- reference point
    axis = {x=0,y=0,z=-1},          -- rotation axis
    angle = 360*RAD                 -- rotation angle
}

-- Spin the third stage and satellite assembly
function third_spin()

  animcomp_Third = oapi.create_animationcomponent(trans_Third)
  anim_Third = vi:create_animation(0)
  vi:add_animationcomponent(anim_Third,0,1,animcomp_Third)

  animcomp_Sat1 = oapi.create_animationcomponent(trans_Sat1)
  anim_Sat1 = vi:create_animation(0)
  vi:add_animationcomponent(anim_Sat1,0,1,animcomp_Sat1)

  local rot1 = vi:get_animation(anim_Third)
  local rot2 = vi:get_animation(anim_Sat1)

  local third_proc = rot1 + da
  local sat1_proc = rot2 + da
  if rot1 < 1 then
    vi:set_animation (anim_Third, third_proc)
  end
  if arm_config == 1 then
    if rot2 < 1 then
      vi:set_animation (anim_Sat1, sat1_proc)
    end
  end

end

-- Spin the jettisoned satellite
function sat_spin()

  animcomp_Sat2 = oapi.create_animationcomponent(trans_Sat2)
  anim_Sat2 = vi:create_animation(0)
  vi:add_animationcomponent(anim_Sat2,0,1,animcomp_Sat2)

  local rot3 = vi:get_animation(anim_Sat2)
  local sat2_proc = rot3 + da2

  if rot3 < 1 then
    vi:set_animation (anim_Sat2, sat2_proc)
  end

end

function clbk_poststep(simt,simdt,mjd)

  da = (simdt * 0.5)
  da2 = (simdt * 0.3)

  if config == 2 then
    third_spin()
  elseif config == 3 then
    sat_spin()
  end

end
 
You create the animation every timestep in config == 3, is that your plan? Also, your satellite can't spin, since the animation stops at rot3 >= 1.0, for rotation, you need a sawtooth pattern by subtracting 1 from rot3 if it exceeds 1.
 
You create the animation every timestep in config == 3, is that your plan? Also, your satellite can't spin, since the animation stops at rot3 >= 1.0, for rotation, you need a sawtooth pattern by subtracting 1 from rot3 if it exceeds 1.
My plan is continuous rotation. I think I'm going about the wrong way.
Here's a video if it helps:
 
Is the stage spinning? I saw some rotation thrusters firing there, not sure if it starts or stops the rotation of the stage, though?
 
Those thrusters are retro thrusters on the second stage. The third stage is inside, it rotates ok. The sat is of course on the third stage.

OK, of course the animation is relative to the rotation of the stage, so it stopped in the end....
 
I'm missing a fundamental problem here somewhere. If you notice I did not create my animations in the "config" section of the third stage or the satellite.
I didn't put them there because they didn't work if I did. They should have though. I'm missing something that should be obvious.
 
I'm missing a fundamental problem here somewhere. If you notice I did not create my animations in the "config" section of the third stage or the satellite.
I didn't put them there because they didn't work if I did. They should have though. I'm missing something that should be obvious.

Do you have a test with a non-rotating third stage? That should make it easier. Also, you should not create the animation again and again, even though its likely harmless, except a surprising behaviour. You might reach the limit for the number of animations maybe. Its in UINT AFAIR, so you can only have 65535 animations per vessel....

And the Urwumpe M.D. tip: Read what each lines of your source code does aloud. Not the just the source code, say what you think the whole line should do and what your code does in detail. Does it really achieve the result that you want? Does it do something more? Does it do something less? If it doubt, read in the Lua language specification what happens and what doesn't happen.
 
Do you have a test with a non-rotating third stage? That should make it easier. Also, you should not create the animation again and again, even though its likely harmless, except a surprising behaviour. You might reach the limit for the number of animations maybe. Its in UINT AFAIR, so you can only have 65535 animations per vessel....

And the Urwumpe M.D. tip: Read what each lines of your source code does aloud. Not the just the source code, say what you think the whole line should do and what your code does in detail. Does it really achieve the result that you want? Does it do something more? Does it do something less? If it doubt, read in the Lua language specification what happens and what doesn't happen.
Yeah, that's what I'm doing now. Luckily it's not that much code.:)
 
Yeah, that's what I'm doing now. Luckily it's not that much code.:)
Maybe also check which meshgroups you animate in each set. I found some overlap there, not sure if you really intended that behavior. But in that version of the code, it shouldn't matter.
 
Maybe also check which meshgroups you animate in each set. I found some overlap there, not sure if you really intended that behavior. But in that version of the code, it shouldn't matter.
Mesh 0 isn't the same mesh every time. I'm clearing the meshes at each stage.
I'll get it pretty soon here. I just need to figure out the continuous rotation with out creating the animation again and again.
 
Creating the animations like this seems to do the trick:
Code:
-- Spin the jettisoned satellite
function sat_spin()

  if sat2_status < 1 then
    vi:set_animation (anim_Sat2, sat2_proc)
  else
    vi:set_animation (anim_Sat2, 0)
  end

end
Thanks!(y)
 
Last edited:
Tip: You can also use

Code:
local sat2_proc = (rot3 + da2) % 1.0

(% = modulo = math.mod)

for letting the rotation cycle between 0 and 1.
 
Back
Top