using UnityEngine; using System.Collections; public class RemoteController : MonoBehaviour { public Joystick leftStick; public Joystick rightStick; public Vector4 yprtRate = new Vector4(35,35,35, 1); public float yaw; public float throlle = 0; public Transform testTransform; public Quaternion targetOrientation; public FlightController targetController; // Use this for initialization void Start () { } // Update is called once per frame void Update () { throlle = Mathf.Clamp01 (leftStick.State.y); yaw += leftStick.State.x * yprtRate.x * Time.deltaTime; Vector2 tiltAxis = rightStick.State; Quaternion rotation = Quaternion.identity; if (tiltAxis.magnitude > 0.01f) { Vector3 rotationAxis = Vector3.Cross(Vector3.up, new Vector3(tiltAxis.x * yprtRate.y, 0, tiltAxis.y * yprtRate.z)); rotation = Quaternion.AngleAxis(rotationAxis.magnitude, rotationAxis.normalized); } //add yaw targetOrientation = Quaternion.AngleAxis (yaw, Vector3.up) * rotation; if (testTransform != null) { testTransform.rotation = targetOrientation; } if (targetController != null) { targetController.targetOrientation = targetOrientation; targetController.targetThrolle = Mathf.Pow (throlle, 1.0f/4.0f) * 0.4f ; } } }