Can this move script be converted to mouse control

i have a purchased asset with a that uses amodified version of the helicopter controller script that is on the internet, i would like to convert it to use mouse to control the pitch and tilt/roll

can anyone help me convert it so it still has the smooth movement that happens when press the keys

thank you in advance

here is control part of script:

 void FixedUpdate()
    {
        LiftProcess();
        MoveProcess();
        TiltProcess();
    }

    private void MoveProcess()
    {
        var turn = TurnForce * Mathf.Lerp(hMove.x, hMove.x * (turnTiltForcePercent - Mathf.Abs(hMove.y)), Mathf.Max(0f, hMove.y));
        hTurn = Mathf.Lerp(hTurn, turn, Time.fixedDeltaTime * TurnForce);
        myRigidbody.AddRelativeTorque(0f, hTurn * myRigidbody.mass, 0f);
        myRigidbody.AddRelativeForce(Vector3.forward * Mathf.Max(0f, hMove.y * ForwardForce * myRigidbody.mass));
    }

    private void LiftProcess()
    {
        var upForce = 1 - Mathf.Clamp(myRigidbody.transform.position.y / EffectiveHeight, 0, 1);
        upForce = Mathf.Lerp (0f, EngineForce, upForce)* myRigidbody.mass;
        myRigidbody.AddRelativeForce(Vector3.up * upForce);
    }

    private void TiltProcess()
    {
        hTilt.x = Mathf.Lerp(hTilt.x, hMove.x * TurnTiltForce, Time.deltaTime);
        hTilt.y = Mathf.Lerp(hTilt.y, hMove.y * ForwardTiltForce, Time.deltaTime);
        myRigidbody.transform.localRotation = Quaternion.Euler(hTilt.y, myRigidbody.transform.localEulerAngles.y, -hTilt.x);
    }

    private void OnKeyPressed(PressedKeyCode[] obj)
    {
        float tempY = 0;
        float tempX = 0;

        // stable forward
        if (hMove.y > 0)
            tempY = - Time.fixedDeltaTime;
        else
            if (hMove.y < 0)
                tempY = Time.fixedDeltaTime;

        // stable lurn
        if (hMove.x > 0)
            tempX = -Time.fixedDeltaTime;
        else
            if (hMove.x < 0)
                tempX = Time.fixedDeltaTime;


        foreach (var pressedKeyCode in obj)
        {
            switch (pressedKeyCode)
            {
                case PressedKeyCode.SpeedUpPressed:

                    EngineForce += 1f;
                    break;
                case PressedKeyCode.SpeedDownPressed:

                    EngineForce -= 1f;
                    if (EngineForce < 0) EngineForce = 0;
                    break;

                    case PressedKeyCode.ForwardPressed:

                    if (IsOnGround) break;
                    tempY = Time.fixedDeltaTime;
                    break;
                    case PressedKeyCode.BackPressed:

                    if (IsOnGround) break;
                    tempY = -Time.fixedDeltaTime;
                    break;
                    case PressedKeyCode.LeftPressed:

                    if (IsOnGround) break;
                    tempX = -Time.fixedDeltaTime;
                    break;
                    case PressedKeyCode.RightPressed:

                    if (IsOnGround) break;
                    tempX = Time.fixedDeltaTime;
                    break;
                    case PressedKeyCode.TurnRightPressed:
                    {
                        if (IsOnGround) break;
                        var force = (turnForcePercent - Mathf.Abs(hMove.y))*myRigidbody.mass;
                        myRigidbody.AddRelativeTorque(0f, force, 0);
                    }
                    break;

                  

                    case PressedKeyCode.TurnLeftPressed:
                    {
                        if (IsOnGround) break;
                       
                        var force = -(turnForcePercent - Mathf.Abs(hMove.y))*myRigidbody.mass;
                        myRigidbody.AddRelativeTorque(0f, force, 0);
                    }
                    break;



            }
            
        }

        hMove.x += tempX;
        hMove.x = Mathf.Clamp(hMove.x, -1, 1);

        hMove.y += tempY;
        hMove.y = Mathf.Clamp(hMove.y, -1, 1);

    }

Steps to success:

  • Identify where the analog inputs for pitch and roll are in the existing code
  • Make sure these original inputs are stored first in some temporary variables (ie., refactor it so they are)
  • Read the mouse motion input for X,Y (see note below!)
  • scale that input according to some amount (mouse arrives scaled to screen coordinates; you need it in whatever form this script expects it in, either degrees or something else)
  • Add the mouse inputs to the temporary copy of the original inputs
  • Use the temporary inputs where the original inputs were supplied

Think of it like “splicing in” a second source of input from the mouse.

Keep in mind also that raw mouse input is positional, whereas joystick input generally is relative. A joystick input of +0.5 means “keep moving at half speed to the right,” but a mouse input of halfway across the screen means “I’m sitting here not moving,” so you need to decide how to control things. One way is to statefully track if the button is down or not.

To this end you might want to start first by printing some values out to Debug.Log() and see what you’re working with, get a feel for the numerics or else it will seem very mystifying to control. You will also need to identify what kind of units are being used with the current input system to do the scaling mentioned above.

thanks for the suggestion, but even using a joystick that seems easier to code than the mouse i still would not know where to begin. thank you

Youtube tutorials are a great to begin! Brackeys probably makes some of the best. The stuff up on the “Learning” tab above is also a great place to start.