using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public float power;
/**
* Every update perform tranlations and rotations based on user input.
* */
void FixedUpdate () {
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement * speed;
// Add the tilt. (When this line is left out, rotation performs as expected)
// When it is left in, the drone rotates but snaps back to it's original orientation on key release.
rigidbody.rotation = Quaternion.Euler (rigidbody.velocity.z, 0.0f, rigidbody.velocity.x * -tilt);
// Ascend.
if (Input.GetKey ("t"))
{
rigidbody.AddRelativeForce (Vector3.up * power);
}
// Descend.
if (Input.GetKey ("g")) {
rigidbody.AddRelativeForce (Vector3.down * power);
}
// Rotate clockwise.
if (Input.GetKey ("h"))
{
transform.Rotate(0, 5, 0, Space.Self);
}
// Rotate anti-clockwise.
if (Input.GetKey ("f"))
{
transform.Rotate(0, -5, 0, Space.Self);
}
}
}