Jump to content

SAS Mode Keybinds [HELP]


Recommended Posts

I'm trying to write a plugin that will switch between the different SAS modes using the num keys. I already have that bit working, when I press a numkey the craft does indeed steer towards the desired vector and stays there. However the little GUI indicators next to the navball don't chage to reflect whatever mode SAS is currently on. It stays on the Stability Assist icon.

My code looks like this(it's probably not very good, this is the first time I try to code a KSP mod)

namespace AutoPilotKeys
{

    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class AutoPilotKeys : MonoBehaviour
    {
        void Update()
        {
            
            if (Input.GetKeyDown(KeyCode.Keypad7)) 
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Prograde); 
            }

            if (Input.GetKeyDown(KeyCode.Keypad9)) 
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.StabilityAssist); 
            }

            if (Input.GetKeyDown(KeyCode.Keypad8)) 
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Retrograde); 
            }

            if (Input.GetKeyDown(KeyCode.Keypad4))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Normal);
            }

            if (Input.GetKeyDown(KeyCode.Keypad5))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Antinormal);
            }

            if (Input.GetKeyDown(KeyCode.Keypad1))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.RadialIn);
            }

            if (Input.GetKeyDown(KeyCode.Keypad2))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.RadialOut);
            }

            if (Input.GetKeyDown(KeyCode.Keypad6))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Target);
            }

            if (Input.GetKeyDown(KeyCode.Keypad3))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.AntiTarget);
            }

            if (Input.GetKeyDown(KeyCode.Keypad0))
            {
                FlightGlobals.ActiveVessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.Maneuver);
            }

        }
    }
}

I thought setting the autopilot mode would automatically make the indicator change to reflect the current mode, but apprently it doesn't. What am I missing?

Link to comment
Share on other sites

You need to find the VesselAutopilotUI and see what you can do with it, but not much seems to be public...

 

Edit : I guess something like

VesselAutopilotUI  ui = FindObjectsOfType(typeof(VesselAutopilotUI )) as VesselAutopilotUI;
for (int i; i<ui.modeButtons.Length; i++)
{
	if ( i == (int)FlightGlobals.ActiveVessel.Autopilot.mode)
		ui.modeButtons[i].Enable(false);
	else
		ui.modeButtons[i].Disable(false);
}

 

Edited by sarbian
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...