Unity Flight Script


SUBMITTED BY: Guest

DATE: Nov. 11, 2013, 9:08 p.m.

FORMAT: Text only

SIZE: 1.1 kB

HITS: 930

  1. using UnityEngine;
  2. using System.Collections;
  3. public class Fly: MonoBehaviour
  4. {
  5. //The purpose of this script is to simulate Newtonian phy
  6. private float maxThrust = 10; //The maximum Thrust provided by the thruster(s) at full throttle
  7. private float rollWeight = 1; //This float and the next two only serve to adjust sensitivity
  8. private float pitchWeight = 1;//of the controls, and to allow calibration for more massive ships.
  9. private float yawWeight = 1;//Set these 3 floats to the mass of the rigidbody for sensitive controls
  10. // Update is called once per frame
  11. void FixedUpdate ()
  12. {
  13. float yaw = yawWeight*Input.GetAxis("Yaw");
  14. float roll = rollWeight*Input.GetAxis("Roll");
  15. float pitch = pitchWeight*Input.GetAxis("Pitch");
  16. Vector3 Rotation = new Vector3(pitch, roll, yaw);
  17. rigidbody.AddRelativeTorque(Rotation);
  18. float throttle = maxThrust *Input.GetAxis("Thrust");
  19. rigidbody.AddRelativeForce(Vector3.down*throttle);
  20. System.Console.WriteLine("input is "+ yaw.ToString()+", "+pitch.ToString()+", "+roll.ToString());
  21. }
  22. }

comments powered by Disqus