Jump to content

How to get and set flight controls


Recommended Posts

I've looked around at different methods for getting and settings flight controls, but none of them have worked, except for the throttle which worked with the following code.

FlightInputHandler.state.mainThrottle = 1.0f;

I'm starting to wonder if it's due to any other addons as the throttle works (only using the code above). The code below is what I've currently got, but it doesn't work.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace TestAdd
{
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class TestAdd : MonoBehaviour
    {
        public void OnStart()
        {
            FlightGlobals.ActiveVessel.OnFlyByWire += MyControlSystem;
        }
        public void MyControlSystem(FlightCtrlState state)
        {
            state.roll = 1f;
            state.pitch = -1f;
            state.mainThrottle= 1f;
        }
        public void OnDestroy()
        {
            FlightGlobals.ActiveVessel.OnFlyByWire -= MyControlSystem;
        }

        public void Update() //This is another method i've tried
        {
            FlightInputHandler.state.roll = 1.0f;
            FlightInputHandler.state.pitch= -1.0f;
        }
    }
}

 

Link to comment
Share on other sites

I guess the piece of code you're showing is just for testing purposes, but you can't do what you're doing from a KSPAddon, because FlightGlobals.ActiveVessel will change when switching vessel, docking, undocking, etc
You need to either use a VesselModule, or alternatively to manage you callback registrations by pooling the active vessel list (technically you can also use GameEvents, but there are many corner case to handle with that approach).

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...