x


Need some help Optimizing this code

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);
}

}
more ▼

asked Apr 29 '10 at 04:06 PM

Fishman92 gravatar image

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.

Apr 29 '10 at 04:10 PM runevision ♦♦
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3570
x680
x492

asked: Apr 29 '10 at 04:06 PM

Seen: 1083 times

Last Updated: Apr 29 '10 at 04:06 PM