コード例 #1
0
    private void OnJoyStick(ref float tempX, ref float tempY)
    {
        Vector3 dir  = Vector3.zero;
        Vector3 dir2 = Vector3.zero;

        dir.x  = joystick.Horizontal();
        dir.z  = joystick.Vertical();
        dir2.x = joystick2.Horizontal();
        dir2.z = joystick2.Vertical();

        //Joystick moving
        EngineForce += dir2.z / 2;       // SpeedUp
        if (EngineForce < 0)
        {
            EngineForce = 0;
        }

        if (!IsOnGround)
        {
            if (dir.x > 0 && Mathf.Abs(dir.x) > Mathf.Abs(dir.z))             // right
            {
                tempX = Time.fixedDeltaTime;
            }
            if (dir.x < 0 && Mathf.Abs(dir.x) > Mathf.Abs(dir.z))             // left
            {
                tempX = -Time.fixedDeltaTime;
            }
            if (dir.z > 0 && Mathf.Abs(dir.z) > Mathf.Abs(dir.x))             // forward
            {
                tempY = Time.fixedDeltaTime;
            }
            if (dir.z < 0 && Mathf.Abs(dir.z) > Mathf.Abs(dir.x))             // back
            {
                tempY = -Time.fixedDeltaTime;
            }

            if (dir2.x > 0 && Mathf.Abs(dir2.x) > Mathf.Abs(dir2.z))                 // turn right
            {
                var force = (turnForcePercent - Mathf.Abs(hMove.y)) * HelicopterModel.mass;
                HelicopterModel.AddRelativeTorque(0f, force, 0);
            }
            if (dir2.x < 0 && Mathf.Abs(dir2.x) > Mathf.Abs(dir2.z))                 // turn left
            {
                var force = -(turnForcePercent - Mathf.Abs(hMove.y)) * HelicopterModel.mass;
                HelicopterModel.AddRelativeTorque(0f, force, 0);
            }
        }
    }