Created
November 16, 2017 05:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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