Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created July 8, 2021 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtdekker/c791d5242d96d68b1b042777f87de639 to your computer and use it in GitHub Desktop.
Save kurtdekker/c791d5242d96d68b1b042777f87de639 to your computer and use it in GitHub Desktop.
Hyper-cheesy-simple non-aerodynamic flight controls.
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