Need some help optimizing this to boost performance, any help appreciated.
//For Flight, no landing etc. Needs Drag and angular drag to work
//speeds, generally for realism put these to high numbers.
var Throttle = -60;
var Brake = 60;
//Rudder
var Rudder = 2;
//Gui Variables
var mphDisplay : GUIText;
var AltDisplay : GUIText;
var DegDisplay : GUIText;
var Warning : GUIText;
function FixedUpdate () {
//print speed
var mph = rigidbody.velocity.magnitude * 2.367 *5;
mphDisplay.text = mph + " mph";
//print Altitude
var altitude = rigidbody.position.y;
AltDisplay.text = altitude - 17 + " Meters";
var degrees = transform.rotation.y;
DegDisplay.text = degrees * 360+ " Degrees";
//height Warning
if (rigidbody.position.y < 40) {
Warning.text = "Pull Up!!";
}
if (rigidbody.position.y > 40) {
Warning.text = " ";
}
if (rigidbody.position.y < 25) {
Warning.text = " ";
}
if (rigidbody.position.y > 1000) {
Warning.text = "Too High, decrease your Altitude";
}
//adds forward motion relative to plane
if (Input.GetKey(KeyCode.Space)) {
rigidbody.AddRelativeForce(Throttle,0,0);
}
//slows plane down, to speed of Constant force- Brake
if (Input.GetKey (KeyCode.LeftAlt)) {
rigidbody.AddRelativeForce(Brake,0,0);
}
//Up, adds torque and upwards force to keep plane stable
if (Input.GetKey (KeyCode.W)) {
rigidbody.AddRelativeTorque(0,0,3);
}
if (Input.GetKey (KeyCode.S)) {
rigidbody.AddRelativeTorque(0,0,-3);
}
//rotates plane, adds torque left
if (Input.GetKey (KeyCode.A)) {
rigidbody.AddRelativeTorque(-8,0,0);
}
//rotates plane, adds torque right
if (Input.GetKey (KeyCode.D)) {
rigidbody.AddRelativeTorque(8,0,0);
}
//Rudder left
if (Input.GetKey (KeyCode.Z)) {
rigidbody.AddRelativeTorque(0,-Rudder,0);
}
//Rudder Right
if (Input.GetKey (KeyCode.X)) {
rigidbody.AddRelativeTorque(0,Rudder,0);
}
}
asked
Apr 29 '10 at 04:06 PM
Fishman92
2.4k
●
101
●
113
●
128
That is not a question and it's not specific. UnityAnswers is for focused questions that may also be useful for others in the future. A general request for help with non-specific optimization is better suited for the forums.