using UnityEngine;
using System.Collections;

public class PlayerFlyController : MonoBehaviour {

	public float forwardMoveSpeed;
	public float rotateSpeed;

	public float forwardMove_SmoothTime;
	public float rotateSpeed_SmoothTime;

	public Transform centerEyeAnchor;

	float forwardMove;
	float forwardMove_Velocity;

	float leftX;
	float leftX_Velocity;
	float leftY;
	float leftY_Velocity;
	
	void Update()
	{
		float rightTrigger = OVRGamepadController.GPC_GetAxis (OVRGamepadController.Axis.RightTrigger);
		float leftTrigger = OVRGamepadController.GPC_GetAxis (OVRGamepadController.Axis.LeftTrigger);

		forwardMove = Mathf.SmoothDamp (forwardMove, rightTrigger - leftTrigger, ref forwardMove_Velocity, forwardMove_SmoothTime);

		transform.position += centerEyeAnchor.forward * Time.deltaTime * forwardMove * forwardMoveSpeed;

		leftX = Mathf.SmoothDamp(leftX, OVRGamepadController.GPC_GetAxis (OVRGamepadController.Axis.LeftXAxis), ref leftX_Velocity, rotateSpeed_SmoothTime);
		leftY = Mathf.SmoothDamp(leftY, OVRGamepadController.GPC_GetAxis (OVRGamepadController.Axis.LeftYAxis), ref leftY_Velocity, rotateSpeed_SmoothTime);

		transform.Rotate (Vector3.right, -1 * rotateSpeed * Time.deltaTime * leftY);
		transform.Rotate (Vector3.up, rotateSpeed * Time.deltaTime * leftX);
		transform.Rotate (centerEyeAnchor.forward, Vector3.Dot(Vector3.forward, centerEyeAnchor.forward) * 	-0.5f * rotateSpeed * Time.deltaTime * leftX);
	}
}
