• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS How to create Switches and Handles in Cockpit

Messages
29
Country
germany
Hello everyone,
I am new in building planes, and I decided to build an old glider like you can see in my pictures below.
It looks quite good already, and I have done four gauges this time.
I am using Blender for the 3D-construction, and I know a little bit about making animations, so my gauges are working good,
and my rudders, speedbrakes and other control-surfaces are doing well too.

Now I like to start creating switches, buttons and handles, for example power-switch or speedbrake-handles.
There are so many questions coming up to me:
- how do I define the mouse-area in Blender ?
- how does the animation of a switch or button have to look like ?
- how many keyframes should a button have, how long should the animation be ?
- what is the syntax of this animation and function in the .xml-file ?

I know, these are many questions to answer, and I am sure, it is not so easy like doing animation only,
but I hope, some of you know how this works, and maybe could help me to realize this project.

Thanks a lot for your help.

1621973052636.png
1621973108254.png
1621973197104.png
1621973257050.png
1621973396837.png
1621973449526.png
 
Messages
29
Country
germany
Hello Devinci,
Thank you for your answer.
Yes, I know about these great "Developement Series" from Brandon.
I had great help in my project with this videos, especially for animations.
But there is not shown the way to make switches, buttons and handels which will work with mouse-clicks.
Maybe one time he will make another video about that ....
 
Messages
34
The easiest way to do this is with the Asobo model behavior templates. The default planes use complex templates to control the specific instruments and controls, but since the model behavior system is based around calling sub templates, you can use any of the sub templates directly for your custom mouse click objects.

This is an example of a switch that has a mouse rect and an animation. In this particular type of switch, it sends different events depending on the position, but there are other switch templates that work on toggles.
XML:
            <Component ID="COM_SELECT" Node="Com_Select_Click">
                <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_MultiStates">
                    <CODE_UP>(&gt;K:COM2_TRANSMIT_SELECT)</CODE_UP>
                    <CODE_DOWN>(&gt;K:COM1_TRANSMIT_SELECT)</CODE_DOWN>
                    <TOOLTIPID>Select COM Transmit</TOOLTIPID>
                </UseTemplate>
                <UseTemplate Name="ASOBO_GT_Anim">
                    <ANIM_NAME>Com_Select_Switch</ANIM_NAME>
                    <ANIM_CODE>(A:COM TRANSMIT:2, Percent)</ANIM_CODE>
                    <ANIM_LENGTH>100</ANIM_LENGTH>
                </UseTemplate>                   
            </Component>
The component ID can be any unique identifier.
Node is the name of the object in Blender
ANIM_NAME is the name of the object action or NLA action from Blender
ANIM_LENGTH matches the number of keyframes in your Blender animation

To find the events you need, refer to the SDK documentation (Event IDs)
Simulation Variables are also listed in the docs (Simulation Vars)

Depending on the value range of the simvar, you may have to multiply it in the ANIM_CODE section. For example, if your simvar is a Boolean, you can multiply by 100 to get a range of 0-100 to match the frames of the animation. <ANIM_CODE>(A:COM TRANSMIT:2, Bool) 100 *</ANIM_CODE> The code section uses RPN notation, so basically the two values go first followed by the operator.

Other basic interaction templates are available in your official packages folder: Official\Steam\fs-base-aircraft-common\ModelBehaviorDefs\Asobo\Generic\Subtemplates\Interactions.xml
Some common ones to use are:
ASOBO_GT_Interaction_LeftSingle_Event or ASOBO_GT_Interaction_LeftSingle_Code for simple toggle switches
ASOBO_GT_Interaction_DraggingAxis_Code is useful for levers and other things you want to move with a mouse
You can also call the ASOBO_GT_MouseRect template by itself which is the base template for the interactions. Just find the XML definition and see what parameters need to be supplied.

Also, you don't have to have the mouse rect on the visible switch object. You can apply the animation to the visible 3D model and create an invisible click area using the collision material. This can be useful if you have small switches that are difficult to click.
 
Messages
29
Country
germany
Hello sal1800

thanks a lot for this information.
That sounds not so easy to me as an animation do. But I will try to find out how this works with your help:

In my example, I like to create a simple lever to move the Speedbrakes up or down. In my project I use the flaps-slider for the speedbrakes, so I am looking for the flaps-event.
Here is the simple lever and it's animation:

1622069090563.png


Here is the syntax of the .xml-file like I think it should be:


<Component ID="FLAPS_switch" Node="FLAPS_Lever"> Component ID=a free name of the funktion Node=a name for the Blender-Object
<UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_MultiStates">
<CODE_UP>(&gt;K:FLAPS_UP)</CODE_UP> the Event-ID for the funktion "FLAPS_UP"
<CODE_DOWN>(&gt;K:FLAPS_DOWN)</CODE_DOWN> the Event-ID for the funktion "FLAPS_DOWN"
<TOOLTIPID>Select FLAPS UP/DOWN</TOOLTIPID> the Popup-text when focus is on the lever
</UseTemplate>
<UseTemplate Name="ASOBO_GT_Anim">
<ANIM_NAME>FLAPS_UP_DOWN</ANIM_NAME> a name for the animation in Blender
<ANIM_CODE>(A:FLAPS HANDLE PERCENT:2, Percent)</ANIM_CODE> is the name of the "AIRCRAFT SIMULATION VARIABLE"
<ANIM_LENGTH>100</ANIM_LENGTH> is the length of the animation in Blender
</UseTemplate>
</Component>

Here is how I set it up in Blender:

1622071491890.png


OK, here is the result of my test:

To bad, it is not working, something have to be wrong !
My lever is shown upside down, I can not handle it with my mouse, and it shows not the defined tooltip-text.
It have no funktion and no animation.
Here is how it looks like in MSFS:

1622075169107.png


Can you tell me, what mistake did I made here ?

Thank you so much.
 
Last edited:
Messages
34
I think you are close but I do see a few issues.

Let's start with the modeling. You have an parent empty with the animation and it's origin in the correct location. The child object (FLAPS_Lever) however should have it's origin in the same location. That's why it is flipping upside down.

The XML for the component is mostly ok but you may need a few more pieces in the file. All model behavior code needs to be inside the <Behaviors> section. And it needs references to the ASOBO templates.
For the animation section, you copied the index number from my example, but since there is only one "flaps", you need to omit that part. This is the :2 in the simvar.

Here is a more complete sample. If the animation is backwards, you can just swap the keyframes in Blender.
XML:
<Behaviors>
    <Include ModelBehaviorFile="Asobo\Common.xml"/>
    <Include ModelBehaviorFile="Asobo\Generic.xml"/>

    <Component ID="FLAPS_switch" Node="FLAPS_Lever">
        <UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_MultiStates">
            <CODE_UP>(&gt;K:FLAPS_UP)</CODE_UP>
            <CODE_DOWN>(&gt;K:FLAPS_DOWN)</CODE_DOWN>
            <TOOLTIPID>Select FLAPS UP/DOWN</TOOLTIPID>
        </UseTemplate>
        <UseTemplate Name="ASOBO_GT_Anim">
            <ANIM_NAME>FLAPS_UP_DOWN</ANIM_NAME>
            <ANIM_CODE>(A:FLAPS HANDLE PERCENT, Percent)</ANIM_CODE>
            <ANIM_LENGTH>100</ANIM_LENGTH>
        </UseTemplate>
    </Component>

</Behaviors>
FLAPS_UP and FLAPS_DOWN only lets you have two positions, but you could use FLAPS_INCR and FLAPS_DECR events which would allow for intermediate positions of the flaps.

I'm curious as to why you are using the Flaps simvars instead of spoilers. This uses the built-in spoiler Asobo template.
XML:
<Behaviors>
    <Include ModelBehaviorFile="Asobo\Common.xml"/>
    <Include ModelBehaviorFile="Asobo\Generic.xml"/>

    <Component ID="SPEEDBRAKES">
        <UseTemplate Name="ASOBO_HANDLING_Switch_Spoiler_Template">
            <ANIM_NAME>FLAPS_UP_DOWN</ANIM_NAME>
            <NODE_ID>FLAPS_Lever</NODE_ID>
            <PART_ID>FLAPS_Lever</PART_ID>
            <TIME_TO_FULL_RANGE_SEC>2</TIME_TO_FULL_RANGE_SEC>
        </UseTemplate>
    </Component>

</Behaviors>
 
Messages
34
My original sample XML was really suited for a panel switch instead of a lever. So here is a better example before I go to bed. You can grab and move to the desired position. Used for flaps, it stops at each notch.
XML:
    <Component ID="FLAPS_switch" Node="FLAPS_Lever">
        <UseTemplate Name="ASOBO_GT_Lever_DraggingYAxis_EventsIncDec">
            <ANIM_NAME>FLAPS_UP_DOWN</ANIM_NAME>
            <ANIM_SIMVAR>FLAPS HANDLE PERCENT</ANIM_SIMVAR>
            <ANIM_SIMVAR_UNITS>percent</ANIM_SIMVAR_UNITS>
            <CLOCKWISE_EVENTID>FLAPS_INCR</CLOCKWISE_EVENTID>
            <ANTICLOCKWISE_EVENTID>FLAPS_DECR</ANTICLOCKWISE_EVENTID>
        </UseTemplate>
    </Component>

In the Blender animation, I right-click the X rotation in the Item panel and use Insert Single Keyframe. This makes the animation a little cleaner because it only contains a single axis rotation.

flaps_lever_blender.png



I guess the cursor didn't show up in the screenshot but it is a grab hand.
The ModelBehaviorDebug shows which values are being used for the animation.

20210527000819_1.jpg
 
Messages
29
Country
germany
Hello sal1800

first I like to thank you so much for spending so many time to help me fixing that problem.
I tried your last XML-example and I was surpriced to see, that my lever ist working as it should do. Thanks !

1622109870704.png


In the MSFS now my mouse-cursor is changing from the arrow to an hand, and I can grap the lever to move it.
1622110300620.png
1622110334441.png
1622110361035.png

... to bad, we don't see the mouse-cursor, but it works - that's so great.

But my lever is still upside down, and I don't have that much experiance in animations with Blender, so I need a little help here too.
How can I set the origin of the FLAPS_Lever to the origin of the empty?
I used the empty-variant of the animation, because the axis of the lever is not parallel to the Blender-axis as you can see here:

1622110906514.png


What steps I have to do, to fix this upside-down-problem? - and maybe I can realize this without an empty - Can you help me please?

To your questions in your last reply:
I'm curious as to why you are using the Flaps simvars instead of spoilers. This uses the built-in spoiler Asobo template.
I got a slider on my Joystick defined for the flaps, and I like to use it in this glider-project for the spoilers. I don't know how to realize this on another way.
But I would like it more, to use the throttle-stick for the spoilers, so I can use both hands to fly the glider. This would be the best ...
In the aircraft-editor I defined 10 positions for the flaps - the handle now stops each position, thats nice. It will be more nice without positions, but still ok like this.

Thank you so much again, I am a lot furher with your help.
 
Messages
29
Country
germany
OK, I could set the origin of the lever to the point of the empty. That looks good.
But now the lever is still upside down, and it is now much to low in the cockpit :(

1622113712359.png
1622113762511.png


Sorry, don't know why ...
 
Messages
34
I am very glad you were able to a working animation. Sadly the documentation on model behaviors is still not available from Microsoft and they are such a powerful new tool. We are left to reverse engineer them.

The parent-child animation in Blender has given me trouble also. To fix, first select the empty and search for the command to Set cursor to Selection.
Then remove the lever from the empty with alt-P, Clear and Keep Transformation. Ensure the lever is in the correct position for the current keyframe. Apply scale and rotation on the lever object.
Search for the command for Set Origin to Cursor. At this point, both origin points should be at the same location. Parent the lever to the empty again.
Any changes to child objects should be done when separated from the parent.
I can't tell from the screenshots, but ensure that the keyframes are only for the rotation, not location.
And if needed, delete all keyframes and create the keyframes again. These are the steps I follow when an animation doesn't match in game.
 
Messages
29
Country
germany
Hi sal1800,

I tried so many things, at least, I build a new lever, but it was not working too.
I have deleted the empty then, and build a little mounting plate for the lever.
Then I defined the lever as child, and the mounting plate as parent.
Afterwards I made a new animation without an empty and set all names like before.
The new lever was then looking so funny in MSFS, you can see it here:

in Blender:
1622150482378.png
... and in MSFS:
1622150555966.png
( isn't it funny ? )

A friend told me, that MSFS got some problems with "Scaled Objects" !
And my new lever had a scalefactor, so I had to set the factor of it's scale to 1.000 . (strg-a > scale)
And now it looks in MSFS the same like I build it in Blender.
That's it, I really got an animated lever, with mouse-move-funktion and lever-info for my speedbrakes.
That is so great !

Thanks a lot for your time, your helpful information and examples.


1622149745320.png
 
Last edited:
Messages
29
Country
germany
Hello sal1800,

I have now builded an switch for my cockpit and tried to get it work.
I like to use it for the Battery-switch On/Off.
OK, I got the switch and the animation in Blender.
The syntax in the xml-file is shown here:

1622257773485.png


It is to bad, that I only found an toggle-switch for the battery, and not the two event IDs Battery On and Off, as the switch-position up and down.
The animation "ELECTRICAL MASTER BATTERY" should show the position of the switch, so I think this is the correct one.

OK, the result is now, that I can switch the battery on and off with my switch at the cockpit, but still toggling, press down it is on, press down again, it is off. Pressing Up is the same.
Thats not what I want.
The other problem is, that my switch in the cockpit is not moving in MSFS. The Text of the ToolTip is correkly shown.

1622258334072.png


Here is the Blender screen:

1622258440500.png


Could you please help me to fix this too?

Thank you very much.
 

Attachments

  • 1622258266469.png
    1622258266469.png
    71.8 KB · Views: 31
Messages
577
Country
france
Hi,

I think that your problem is located in the instruction <CODE_UP> and <CODE_DOWN>
You send the same value for two actions so you obtain the same thing for the two actions..

Try 1 (&gt;K:TOOGLE_MASTER_BATTERY) for CODE_UP and 0 (&gt;K:TOOGLE_MASTER_BATTERY) for CODE_DOWN for example :cool:
 
Messages
445
Country
austria
You are missing a comma. After BATTERY:2 should be the comma...........................................||
(A:ELECTRICAL MASTER BATTERY:2 Bool) sholuld be (A:ELECTRICAL MASTER BATTERY:2,Bool)

And i'm not sure if you can (A:ELECTRICAL MASTER BATTERY:2,Bool).
Test it without 2 ..(A:ELECTRICAL MASTER BATTERY,Bool)
And no need to write 0 or 1 in front of the K: event

btw very nice Ka7!!
 
Messages
29
Country
germany
Hello EduHir,

thanks for your help, and thank you for your praise to my K7.
I like this glider so much, because I had my first flight ever on this glider when i was about 8 years old.
And now it is my first plane I am creating for MSFS.:)

I tried your suggestion and I got a small success:
My switch is moving, but only a very small way, maybe about 2% of the complete way (2 keyframes from 100).
But it is moving, and it can not be very far from a complete working switch.
Your information about the missing comma was a good note.

What can I do now? Maybe I should shorten the animation in Blender to 2 keyfames? Or is it not the right way?

Another question is:
Could I put only one Code-Line in the xml-file? because my mousecursor shows to arrows when I move it over the switch,
one arrow up, and one arrow down dependency of the upper or lower area of the switch.
but my eventID is an toggle-switch, so normally I have to use a one-position-switch, first press ON, second press OFF.
But if we could nod fix this, it will not be a problem with the two small arrows...

Here is hte xml-file:

1622317776544.png


Thanks a lot for your help.
 
Messages
34
As EduHir pointed out, you do not want the :2 in the code. That is used when there are multiple instances of a particular simvar. Like if you had two batteries, you could assign switches to each one.

For your case, (A:ELECTRICAL MASTER BATTERY,Bool) is the correct code.

For systems that toggle, it is best to use this other switch template that uses just one event or code. Either of these will work.

XML:
<UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Event">
    <TOOLTIPID>Switch MASTER Battery %((A:ELECTRICAL MASTER BATTERY, Bool))%{if}OFF%{else}ON%{end}</TOOLTIPID>
    <EVENTID>TOGGLE_MASTER_BATTERY</<EVENTID>
</UseTemplate>  

<UseTemplate Name="ASOBO_GT_Interaction_LeftSingle_Code">
    <TOOLTIPID>Switch MASTER Battery %((A:ELECTRICAL MASTER BATTERY, Bool))%{if}OFF%{else}ON%{end}</TOOLTIPID>
    <LEFT_SINGLE_CODE>(&gt;K:TOGGLE_MASTER_BATTERY)</LEFT_SINGLE_CODE>
    <EVENTID/>
</UseTemplate>

Your modeling and details look very good! This should be a fun glider to fly.
 
Messages
29
Country
germany
OK, I tried it without the :2 this time.
It works like before, with the two arrows showing.
But what is the problem, that the swtich will only move the small way?

And a question to your examples:
Where do I declaire the name oft the switch in Blender and the name of the animation?

Thanks.
 
Last edited:
Messages
445
Country
austria
At the older FS - versions we can define the cursuor like

XML:
    <Cursor Type="Hand"/>
So you have to look at the docu. Or open a new thread here and ask for it. Maybe someone knows how to change the cursor in MSFS.

(A:ELECTRICAL MASTER BATTERY,Bool) gives 0 or 1. I'm only a XML programmer. you need a modeler!
 
Top