Question Implementing Parent / Child Animations in Lua?

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,242
Reaction score
3,138
Points
138
Location
Massachusetts
I am trying to establish an animation of a rotating wheel on a landing gear strut.

I have an animation of the wheel that causes it to rotate about its axle when the vessel is rolling, defined as follows:

Code:
anim_wheel1 = vi:create_animation(0)

wheel1 =
    {
    type =  'rotation',
    mesh =  0,
    grp =   {124, 125},
    ref =   {x=0, y=-2.24121, z=2.879426},
    axis =  {x=1,y=0,z=0},
    angle = 360*RAD
    }

rot_wheel1 = oapi.create_animationcomponent(wheel1)

vi:add_animationcomponent(anim_wheel1, 0, 1, rot_wheel1)

There is another animation that allows for the gear strut this wheel is mounted on to retract / deploy:

Code:
gear1 =
    {
    type =  'rotation',
    mesh =  0,
    grp =   {6, 7, 8, 13, 52},
    ref =   {x=0,y=-1.204259,z=3.27775},
    axis =  {x=1,y=0,z=0},
    angle = 95*RAD
    }

anim_gear = vi:create_animation(gear_anim_state)

nose_gear = oapi.create_animationcomponent(gear1)

vi:add_animationcomponent(anim_gear, 0.5, 1, nose_gear)

At this point these animations are independent, but what is needed is to add the wheel to the landing gear strut such that it will rotate around its axle AND rotate with the gear as it retracts or deploys.

I've tried something like this to establish the parent/child animation:

Code:
vi:add_animationcomponent(anim_wheel1, 0.5, 1, rot_wheel1, nose_gear)

But this causes Orbiter to freeze up. I'm not sure what the problem is. I have a number of other animations working fine, but this one with two transformations isn't cooperating. Does anyone see what the problem is? I've been rummaging through the Lua examples trying to find a parent/child animation but haven't seen one.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,242
Reaction score
3,138
Points
138
Location
Massachusetts
Apparently it needs to go something like this:

Code:
anim_wheel1 = vi:create_animation(0)

wheel1 =
        {
        type =  'rotation',
        mesh =  0,
        grp =   {124, 125},
        ref =   {x=0, y=-2.2405, z=2.8794},
        axis =  {x=1,y=0,z=0},
        angle = 360*RAD
        }

rot_wheel1 = oapi.create_animationcomponent(wheel1)

    gear1 =
        {
        type =  'rotation',
        mesh =  0,
        grp =   {6, 7, 8, 13, 52},
        ref =   {x=0,y=-1.204259,z=3.27775},
        axis =  {x=1,y=0,z=0},
        angle = 95*RAD
        }

anim_gear = vi:create_animation(gear_anim_state)
    
nose_gear = vi:add_animationcomponent(anim_gear, 0, 0.5, oapi.create_animationcomponent(gear1))

vi:add_animationcomponent(anim_wheel1, 0, 1, rot_wheel1, nose_gear)
 
Top