Created
November 29, 2021 20:25
-
-
Save MattGen/327284c926ec459c387d007a28f8f916 to your computer and use it in GitHub Desktop.
Rust-like mini copter code (Unity)
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.Generic; | |
using UnityEngine; | |
public class CopterControl : MonoBehaviour | |
{ | |
public float thrust; | |
public ForceMode forceMode; | |
public float rotSpeed; | |
void Update() | |
{ | |
if(Input.GetKey(KeyCode.Z)) | |
{ | |
gameObject.GetComponent<Rigidbody>().AddRelativeForce(Vector3.up*thrust,forceMode); | |
} | |
if(Input.GetKey(KeyCode.S)){gameObject.GetComponent<Rigidbody>().AddRelativeForce(-Vector3.up*thrust,forceMode);} | |
if(Input.GetKey(KeyCode.Q)){gameObject.GetComponent<Rigidbody>().AddTorque(Vector3.up*-rotSpeed,forceMode);} | |
if(Input.GetKey(KeyCode.D)){gameObject.GetComponent<Rigidbody>().AddTorque(Vector3.up*rotSpeed,forceMode);} | |
gameObject.transform.Rotate(Vector3.right,Input.GetAxis("Mouse Y"), Space.Self); | |
gameObject.transform.Rotate(-Vector3.forward,Input.GetAxis("Mouse X"), Space.Self); | |
if(Input.GetButton("Fire1")){CopterFire();} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment