NWH Aerodynamics
Search Results for

    Show / Hide Table of Contents

    Input

    NWH Aerodynamics uses the provider registry from NWH Common.

    • Each aircraft has an AircraftInputManager and an AircraftInputStates value.
    • Aircraft controls come from scene-global components derived from AircraftInputProviderBase.
    • Camera and scene controls come from separate components derived from SceneInputProviderBase.
    • Matching numeric provider values are added; matching Boolean values are combined with logical OR.

    The aircraft input types are in NWH.Aerodynamics.AircraftController.Input. The shared InputProvider registry is in NWH.Common.Input.

    Important

    Normally add one aircraft provider for the player's input source. Every enabled aircraft reads the same scene-global contribution. Duplicate providers duplicate numeric input.

    Input System setup

    The package manifest declares Input System 1.11.2.

    1. In Edit > Project Settings > Player, set Active Input Handling to Input System Package (New), or Both when the project also needs legacy Input Manager input.
    2. Add one InputSystemAircraftInputProvider to an active scene GameObject.
    3. Add an InputSystemSceneInputProvider only when the scene also needs shared camera, vehicle-changing, character, or demo-UI controls.

    The aircraft provider creates and enables the generated AircraftInputActions wrapper. There is no action-asset reference to assign in its inspector. The shipped asset and wrapper are frozen for deterministic package imports; use runtime rebinding or a project-owned action asset/provider for project-specific controls instead of editing a registry package cache. Package maintainers changing the action asset in a writable embedded package must temporarily enable Generate C# Class, save and regenerate the wrapper, review it, and disable generation again before redistribution.

    Shipped aircraft bindings

    These values come directly from the current AircraftInputActions asset. Negative and positive labels describe the value supplied by a one-dimensional composite.

    Elevator input follows flight-stick controls: positive input (W or stick up) pitches the nose down, and negative input (S or stick down) pitches the nose up. Elevator trim up and down adjust the nose in the named direction.

    Action Keyboard Gamepad
    Ailerons A negative, D positive Left stick left negative, right positive
    AileronsTrimLeft H North + D-pad left
    AileronsTrimRight K North + D-pad right
    Rudder Q negative, E positive Left trigger negative, right trigger positive
    RudderTrimLeft Y Unbound
    RudderTrimRight I Unbound
    Elevator S negative, W positive Left stick down negative, up positive
    ElevatorTrimUp U North + D-pad up
    ElevatorTrimDown J North + D-pad down
    FlapsExtend F7 Right shoulder
    FlapsExtendFully F8 Unbound
    FlapsRetract F6 Left shoulder
    FlapsRetractFully F5 Unbound
    Spoilers Slash Unbound
    LandingLights L Unbound
    NavigationLights N Unbound
    LandingGear G Unbound
    EngineStartCommon T West
    EngineStopCommon F North + Right stick press
    ThrottleCommon Unbound Unbound
    ThrottleIdle F1 Unbound
    ThrottleIncrease F3 South
    ThrottleDecrease F2 East
    ThrottleFull F4 Unbound
    ParkingBrake Comma North + East
    Brakes Period North
    BrakesLeft Minus Unbound
    BrakesRight Equals Unbound
    SmokeSystem O Unbound
    PropPitch F9 negative, F10 positive Unbound
    PropPitchIncrease F12 Unbound
    PropPitchDecrease F11 Unbound

    Rebind any actions you plan to use together through the AircraftInputActions asset for the Input System, or through InputBindings.txt for the legacy Input Manager.

    Spoilers, ThrottleCommon, PropPitchIncrease and PropPitchDecrease are collected into AircraftInputManager but no package component acts on them. Read them from your own scripts, or use the controls the package does act on: the throttle commands (ThrottleIdle, ThrottleIncrease, ThrottleDecrease, ThrottleFull) and the absolute PropPitch axis, which PropellerPropulsor binds through its pitchInputBinding.

    Legacy Input Manager

    InputManagerVehicleInputProvider is the current aircraft provider for Unity's legacy Input Manager. Despite its historical class name, it derives from AircraftInputProviderBase in the Aerodynamics assembly.

    1. Set Active Input Handling to Input Manager (Old) or Both.
    2. Add one InputManagerVehicleInputProvider to an active scene GameObject.
    3. Add the axes and buttons from Runtime/AircraftController/Input/InputProviders/InputManager/InputBindings.txt to Edit > Project Settings > Input Manager.
    4. Add an InputManagerSceneInputProvider only when Common scene controls are also needed.

    The Input System remains a declared package dependency. The legacy aircraft provider also uses the Input System's mouse device when its mouseInput option is enabled.

    Reading combined input

    Use AircraftInputProviderBase as the generic argument when all aircraft providers should contribute:

    using NWH.Aerodynamics.AircraftController.Input;
    using NWH.Common.Input;
    using UnityEngine;
    
    public sealed class AircraftInputReader : MonoBehaviour
    {
        private void Update()
        {
            float ailerons =
                InputProvider.CombinedInput<AircraftInputProviderBase>(
                    provider => provider.Ailerons());
            bool landingGear =
                InputProvider.CombinedInput<AircraftInputProviderBase>(
                    provider => provider.LandingGear());
    
            if (landingGear)
            {
                Debug.Log($"Landing-gear input; ailerons were {ailerons}.");
            }
        }
    }
    

    When a reference to a specific provider is already available, call that component directly.

    Setting aircraft input from code

    Set autoSetInput to false before an AI or another script writes the manager. Then use the manager's public properties or the matching fields in AircraftInputStates.

    using NWH.Aerodynamics.AircraftController.Input;
    using UnityEngine;
    
    public sealed class AircraftAiInput : MonoBehaviour
    {
        [SerializeField] private AircraftInputManager inputManager;
        [SerializeField, Range(-1f, 1f)] private float ailerons;
        [SerializeField, Range(-1f, 1f)] private float elevator;
    
        private void Awake()
        {
            inputManager.autoSetInput = false;
        }
    
        private void Update()
        {
            inputManager.Ailerons = ailerons;
            inputManager.Elevator = elevator;
        }
    }
    

    The manager resets one-frame Boolean states during its update cycle. Write continuous values each frame and pulse command values only when the command should occur.

    Creating a custom provider

    Derive from AircraftInputProviderBase and override only the controls supplied by the new source. The base implementations return neutral values.

    using NWH.Aerodynamics.AircraftController.Input;
    using UnityEngine;
    
    public sealed class ExampleAircraftInputProvider : AircraftInputProviderBase
    {
        [SerializeField, Range(-1f, 1f)] private float ailerons;
    
        public override float Ailerons()
        {
            return ailerons;
        }
    }
    

    Add the custom component once in the scene. Leave another aircraft provider registered only when its values are intended to be combined. Disabling the component or its GameObject does not remove it from InputProvider.Instances; remove or destroy an unwanted provider so OnDestroy() unregisters it.

    In this article
    Back to top Copyright © NWH - Vehicle Physics, Aerodynamics, Dynamic Water Physics