コード例 #1
0
    public void UpdateOutputs()
    {
        // engine 1 thrust x2
        // engine 2 thrust x2

        // engine 1 tilt x2
        // engine 2 tilt x2

        // gyro x2

        AHKController.SetEnginePower(AHKController.EngineType.Left, (Outputs[0].currentValue - Outputs[1].currentValue + 1) / 2f);
        AHKController.SetEnginePower(AHKController.EngineType.Right, (Outputs[2].currentValue - Outputs[3].currentValue + 1) / 2f);

        AHKController.SetEngineTilt(AHKController.EngineType.Left, Outputs[4].currentValue - Outputs[5].currentValue);
        AHKController.SetEngineTilt(AHKController.EngineType.Right, Outputs[6].currentValue - Outputs[7].currentValue);

        AHKController.SetGyroPower(Outputs[8].currentValue - Outputs[9].currentValue);
    }
コード例 #2
0
ファイル: JoystickFlight.cs プロジェクト: Bullshitzu/AHK
    void Update()
    {
        // Engines

        float roll = Input.GetAxis("Joy X");
        float ver  = Input.GetAxis("Joy Y");

        float climb = Input.GetAxis("Vertical");
        float yaw   = Input.GetAxis("Horizontal");

        roll  = Mathf.Abs(Mathf.Pow(roll, nonlinearityRoll)) * (roll < 0 ? -1 : 1);
        ver   = Mathf.Abs(Mathf.Pow(ver, nonlinearityPitch)) * (ver < 0 ? -1 : 1);
        yaw   = Mathf.Abs(Mathf.Pow(yaw, nonlinearityYaw)) * (yaw < 0 ? -1 : 1);
        climb = Mathf.Abs(Mathf.Pow(climb, nonlinearityClimb)) * (climb < 0 ? -1 : 1);

        roll = (roll + 1) / 2;

        AHKController.SetEngineTilt(AHKController.EngineType.Left, yaw - ver);
        AHKController.SetEngineTilt(AHKController.EngineType.Right, -yaw - ver);

        AHKController.SetEnginePower(AHKController.EngineType.Left, roll + climb);
        AHKController.SetEnginePower(AHKController.EngineType.Right, 1 - roll + climb);

        // Gyro

        float angle = AHKController.instance.transform.localRotation.eulerAngles.x;

        if (angle > 180)
        {
            angle = -(360 - angle);
        }

        Vector3 localangularvelocity = AHKController.instance.transform.InverseTransformDirection(AHKController.instance.GetComponent <Rigidbody>().angularVelocity).normalized
                                       *AHKController.instance.GetComponent <Rigidbody>().angularVelocity.magnitude;

        AHKController.SetGyroPower(-angle / 15 - localangularvelocity.x);
    }