• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joe_coronado · May 27, 2012 at 04:02 PM · pitchaeroplane

Need Help for aeroplane scrip

Hi guys, for some reason my aeroplane script will not allow me to pitch upwards can you guys have alook at it thanks.

 var flyer : Transform;

var flyerRigidbody : Rigidbody; var seaLevelTransform : Transform;

// Assorted control variables. These mostly handle realism settings, change as you see fit. var accelerateConst: float = 5; // Set these close to 0 to smooth out acceleration. Don't set it TO zero or you will have a division by zero error. var decelerateConst: float = 0.065; // I found t$$anonymous$$s value gives semi-realistic deceleration, change as you see fit.

 /*    The ratio of MaxSpeed to Speed Const determines your true max speed. The formula is maxSpeed/SpeedConst = True Speed. 
     T$$anonymous$$s way you wont have to scale your objects to make them seem like they are going fast or slow.
     MaxSpeed is what you will want to use for a GUI though.
 */ 
 static var maxSpeed : float = 100;        
 var speedConst : float = 50;
 
 var throttleConst : int = 50;
 var raiseFlapRate : float = 1;                        // Smoother when close to zero
 var lowerFlapRate : float = 1;                        // Smoother when close to zero
 var maxAfterburner : float = 5;                // The maximum thrust your afterburner will produce
 var afterburnerAccelerate : float = 0.5;
 var afterburnerDecelerate : float = 1;
 var liftConst : float = 7.5;                    // Another arbitrary constant, change it as you see fit.
 var angleOfAttack : float = 15;            // Effective range: 0 <= angleOfAttack <= 20
 var gravityConst = 9.8;                // An arbitrary gravity constant, there is no particular reason it has to be 9.8...
 var levelFlightPercent : int = 25;
 var maxDiveForce : float = 0.1;
 var noseDiveConst : float = 0.01;
 var minSmooth : float = 0.5;
 var maxSmooth : float = 500;
 var maxControlSpeedPercent : float = 75;        // When your speed is withen the range defined by these two variables, your s$$anonymous$$p's rotation sensitivity fluxuates.
 var minControlSpeedPercent : float = 25;        // If you reach the speed defined by either of these, your s$$anonymous$$p has reached it's max or min sensitivity.


// Rotation Variables, change these to give the effect of flying anyt$$anonymous$$ng from a cargo plane to a fighter jet. var lockRotation : boolean; // If t$$anonymous$$s is checked, it locks pitch roll and yaw constants to the var rotationConst. var lockedRotationValue : int = 120; var pitchConst = 100; var rollConst = 100; var yawConst = 100;

// Airplane Aerodynamics - I strongly reccomend not touc$$anonymous$$ng these... private var nosePitch : float; private var trueSmooth : float; private var smoothRotation : float; private var truePitch : float; private var trueRoll : float; private var trueYaw : float; private var trueThrust : float; static var trueDrag : float;

// Misc. Variables static var afterburnerConst : float; static var altitude : int;

// HUD and Heading Variables. Use these to create your insturments. static var trueSpeed : int; static var attitude : int; static var incidence : int; static var bank : int; static var heading : int;

// Let the games begin! function Start () { trueDrag = 0; afterburnerConst = 0; smoothRotation = minSmooth + 0.01; if (lockRotation == true) { pitchConst = lockedRotationValue; rollConst = lockedRotationValue; yawConst = lockedRotationValue; Screen.showCursor = false; } }

function Update () {

 // * * T$$anonymous$$s section of code handles the plane's rotation.
 
 var pitch = -Input.GetAxis ("Pitch") * pitchConst;
 var roll = Input.GetAxis ("Roll") * rollConst;
 var yaw = -Input.GetAxis ("Yaw") * yawConst;

 pitch *=  Time.deltaTime;
 roll *= -Time.deltaTime;
 yaw *= Time.deltaTime;
 
 // Smot$$anonymous$$ng Rotations...    
 if ((smoothRotation > minSmooth)&&(smoothRotation < maxSmooth))
 {
     smoothRotation = Mathf.Lerp (smoothRotation, trueThrust, (maxSpeed-(maxSpeed/minControlSpeedPercent))* Time.deltaTime);
 }
 if (smoothRotation <= minSmooth)
 {
     smoothRotation = smoothRotation +0.01;
 }
 if ((smoothRotation >= maxSmooth) &&(trueThrust < (maxSpeed*(minControlSpeedPercent/100))))
 {
     smoothRotation = smoothRotation -0.1;
 }
 trueSmooth = Mathf.Lerp (trueSmooth, smoothRotation, 5* Time.deltaTime);
 truePitch = Mathf.Lerp (truePitch, pitch, trueSmooth * Time.deltaTime);
 trueRoll = Mathf.Lerp (trueRoll, roll, trueSmooth * Time.deltaTime);
 trueYaw = Mathf.Lerp (trueYaw, yaw, trueSmooth * Time.deltaTime);



 

// T$$anonymous$$s next block handles the thrust and drag. var throttle = (((-(Input.GetAxis ("Throttle"))+1)/2)*100);

 if ( throttle/speedConst >= trueThrust)
 {
     trueThrust = Mathf.SmoothStep (trueThrust, throttle/speedConst, accelerateConst * Time.deltaTime);
 }
 if (throttle/speedConst < trueThrust)
 {
     trueThrust = Mathf.Lerp (trueThrust, throttle/speedConst, decelerateConst * Time.deltaTime);
 }    

 rigidbody.drag = liftConst*((trueThrust)*(trueThrust));
 
 if (trueThrust <= (maxSpeed/levelFlightPercent))
 {
     
     nosePitch = Mathf.Lerp (nosePitch, maxDiveForce, noseDiveConst * Time.deltaTime);
 }
 else
 {
     
     nosePitch = Mathf.Lerp (nosePitch, 0, 2* noseDiveConst * Time.deltaTime);
 }
 
 trueSpeed = ((trueThrust/2)*maxSpeed);
 

// ** Additional Input

 // Airbrake
 if (Input.GetButton ("Airbrake"))
 {
     trueDrag = Mathf.Lerp (trueDrag, trueSpeed, raiseFlapRate * Time.deltaTime);        
     
 }
 
 if ((!Input.GetButton ("Airbrake"))&&(trueDrag !=0))
 {
     trueDrag = Mathf.Lerp (trueDrag, 0, lowerFlapRate * Time.deltaTime);
 }
 
 
 // Afterburner
 if (Input.GetButton ("Afterburner"))
 {
     afterburnerConst = Mathf.Lerp (afterburnerConst, maxAfterburner, afterburnerAccelerate * Time.deltaTime);        
 }
 
 if ((!Input.GetButton ("Afterburner"))&&(afterburnerConst !=0))
 {
     afterburnerConst = Mathf.Lerp (afterburnerConst, 0, afterburnerDecelerate * Time.deltaTime);
 }
 
 
 // Adding nose dive when speed gets below a percent of your max speed    
 if ( ((trueSpeed - trueDrag) + afterburnerConst) <= (maxSpeed*levelFlightPercent/100))
 {
     noseDiveConst = Mathf.Lerp (noseDiveConst,maxDiveForce, (((trueSpeed - trueDrag) + afterburnerConst) - (maxSpeed * levelFlightPercent/100)) *5 *Time.deltaTime);
     flyer.Rotate(noseDiveConst,0,0,Space.World);        
 }
 
 
 // Calculating Flight Mechanics. Used mostly for the HUD.
 attitude = parseInt(-((Vector3.Angle(Vector3.up, flyer.forward))-90));
 bank = parseInt(((Vector3.Angle(Vector3.up, flyer.up))));    
 incidence = attitude + angleOfAttack;
 heading = parseInt(flyer.eulerAngles.y);
 
 if ( seaLevelTransform != null )
 {
 altitude = (flyer.transform.position.y - seaLevelTransform.transform.position.y);
 }
 //Debug.Log ((((trueSpeed - trueDrag) + afterburnerConst) - (maxSpeed * levelFlightPercent/100)));

} // End function Update( );

function FixedUpdate () { if (trueThrust <= maxSpeed) { // Horizontal Force transform.Translate(0,0,((trueSpeed - trueDrag)/100 + afterburnerConst)); }

 flyerRigidbody.AddForce (0,(rigidbody.drag - gravityConst),0);
 transform.Rotate (truePitch,-trueYaw,trueRoll);
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kolban · May 27, 2012 at 04:47 PM 1
Share

I think there are some formatting issues. Can you see if you can make the body of the post all one code formatted block for readability? If you are looking for assistance, you need to spend time making your question as readable as possible. Since this is a LOT of code, you are making the responders work hard.

avatar image whydoidoit · May 27, 2012 at 05:12 PM 0
Share

You can edit your question - highlight the code using the mouse and click on the button with the "101" at the top to format the code for you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by joe_coronado · May 27, 2012 at 06:23 PM

Hi guys thanks for your answers about readability the code has pasted 3 times just read the top box thanks,

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How would I get camera bobbing? 0 Answers

Error UCE0001 ";"Expected 2 Answers

Unity mathematics phrasing. 1 Answer

Changing or replace objects 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges