Skip to content

Instantly share code, notes, and snippets.

@runewake2
Created November 16, 2017 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save runewake2/59256e503fa8c960ccef7157c994aa37 to your computer and use it in GitHub Desktop.
Save runewake2/59256e503fa8c960ccef7157c994aa37 to your computer and use it in GitHub Desktop.
The basic 6 Degrees of Freedom Spaceship controller build as a part of 6 Degrees Of Freedom Spaceship - The Wrong Way video: https://youtu.be/C7PtRXH3e-Y
using UnityEngine;
// Basic flight controller designed to demonstrate Gimble Locking in 3D space.
// This works by calculating rotation based on Euler angles instead of other methods.
public class FlightController : MonoBehaviour
{
public float speed;
public float rotationSpeed;
void Update ()
{
var rotation = this.transform.rotation.eulerAngles;
rotation += new Vector3(
Input.GetAxis("Pitch") * rotationSpeed * Time.deltaTime,
Input.GetAxis("Yaw") * rotationSpeed * Time.deltaTime,
Input.GetAxis("Roll") * rotationSpeed * Time.deltaTime);
this.transform.rotation = Quaternion.Euler(rotation);
this.transform.position += this.transform.forward * Input.GetAxis("Vertical") * speed * Time.deltaTime;
this.transform.position += this.transform.right * Input.GetAxis("Horizontal") * speed * Time.deltaTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment