Created
July 8, 2021 17:05
-
-
Save kurtdekker/c791d5242d96d68b1b042777f87de639 to your computer and use it in GitHub Desktop.
Hyper-cheesy-simple non-aerodynamic flight controls.
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// @kurtdekker | |
// | |
// Hyper-cheesy non-aerodynamic flight controls | |
// | |
// To use: | |
// - slap this on your camera | |
// - move the camera where you want it to start | |
// - press PLAY | |
public class HyperSimpleFlightControls : MonoBehaviour | |
{ | |
// gathered inputs | |
float horizontal; | |
float vertical; | |
// your input coupled to roll | |
float rollRate = 90; | |
// your input coupled to pitch | |
float pitchRate = 50; | |
// the bank angle coupled to yaw (turning) | |
float BankToTurnCoupling = 60; | |
float airspeed = 20; | |
void UpdatGatherInput() | |
{ | |
// replace with whatever you want here... new input system or whatever | |
horizontal = -Input.GetAxis( "Horizontal"); | |
vertical = Input.GetAxis( "Vertical"); | |
} | |
void UpdateFlightDynamics() | |
{ | |
// roll | |
transform.Rotate( Vector3.forward, horizontal * rollRate * Time.deltaTime); | |
// pitch | |
transform.Rotate( Vector3.right, vertical * pitchRate * Time.deltaTime); | |
// couple yaw to roll angle - pure cheese - only works to a point | |
transform.Rotate( Vector3.up, -transform.right.y * BankToTurnCoupling * Time.deltaTime); | |
// move | |
transform.position += transform.forward * (airspeed * Time.deltaTime); | |
} | |
void Update () | |
{ | |
UpdatGatherInput(); | |
UpdateFlightDynamics(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment