Question [SOLVED] Flight Control Animations Not Working In Lua

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I am trying to convert some of my C++ add-on modules into Lua scripts. One problem I am having is getting the flight control animations to work.

For example, here is the elevator implementation

In clbk_setclasscaps(cfg):

Code:
vi:create_controlsurface(AIRCTRL.ELEVATOR, 7, 0.7, {x=0, y=0, z=-17}, AIRCTRL_AXIS.XPOS, anim_elevator)

anim_elevator = vi:create_animation(0.5)

elevator =
        {
        type =  'rotation',
        mesh =  0,
        grp =   {134,142},
        ref =   {x=0,y=-0.9223039,z=-4.268489},
        axis =  {x=1,y=0,z=0},
        angle = 33*RAD
        }
  
vi:add_animationcomponent(anim_elevator,0,1,oapi.create_animationcomponent(elevator))

This script runs, but when I test fly the aircraft, the elevator applies a force, but the corresponding animation doesn't work.

This is the corresponding code in my C++ module:

In clbkSetClassCaps(FILEHANDLE cfg):

C++:
    CreateControlSurface(AIRCTRL_ELEVATOR, 7, 0.7, _V(0, 0, -17), AIRCTRL_AXIS_XPOS, anim_elevator);

In DefineAnimations(void):

C++:
    static UINT EGrp1[2] = { 134, 142 };
    static MGROUP_ROTATE elevator(0, EGrp1, 2, _V(0, -0.9223039, -4.268489), _V(1, 0, 0), (float)(33 * RAD));
    anim_elevator = CreateAnimation(0.5);
    AddAnimationComponent(anim_elevator, 0, 1, &elevator);

I have other animations working like wheels, but none of the flight control animations want to work, yet the script runs and I can't see any obvious problems with my script code. Can anybody with fresh eyes see what I am missing?

Additional information: I can set the animation state using vi:set_animation(anim_elevator, 1) in clbk_poststep() and that moves the elevator mesh. Do I explicitly have to pass the flight control inputs to the animations? I thought they were already linked when the control surface was created?
 
Last edited:

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,367
Reaction score
3,302
Points
138
Location
Massachusetts
I'm no expert but perhaps you need the delay.
Code:
vi:create_controlsurface(AIRCTRL.ELEVATOR, 7, 0.7, {x=0, y=0, z=-17}, AIRCTRL_AXIS.XPOS, 0.5, anim_elevator)
It seems that there were two problems. The supposedly optional delay setting doesn't seem to be optional. I have set it to 1. It doesn't seem to do anything if a value is not provided.

Also, it seems the control surface creation needs to occur after the animation creation. The following works:

Code:
    -- Elevator animation

    anim_elevator = vi:create_animation(0.5)

    elevator =
        {
        type =  'rotation',
        mesh =  0,
        grp =   {134, 142},
        ref =   {x=0,y=-0.9223039,z=-4.268489},
        axis =  {x=1,y=0,z=0},
        angle = 33*RAD
        }
    
    vi:add_animationcomponent(anim_elevator,0,1,oapi.create_animationcomponent(elevator))

    vi:create_controlsurface(AIRCTRL.ELEVATOR, 7, 0.7, {x=0, y=0, z=-17}, AIRCTRL_AXIS.XPOS, 1, anim_elevator)
    vi:create_controlsurface(AIRCTRL.ELEVATORTRIM, 5, 0.1, {x=0, y=0, z=-17}, AIRCTRL_AXIS.XPOS, 1, anim_elevator)
 
Top