Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Fred 4 · May 23, 2011 at 12:18 AM · javascriptinputcontrol

Control left + right = up

Hey guys, i'm making a project that i'm creating a physical control, when the user go left with your weight he press the button left, if he go right, he press right and if he press left + right he press up. I done a script but withous this, i need this because i have only 3 buttons on my project.

See the Script

 var gameover=0;
 static var airplaneangley: float=0.0;
 //Rotaton and position of our airplane
 var rotationx=0;
 var rotationy=0;
 var rotationz=0;
 var positionx: float=0.0;
 var positiony: float=0.0;
 var positionz: float=0.0;
 
 var speed:float =0.0;// speed variable is the speed
 var uplift:float =0.0;
 
 function Update () {


     // shadow to the same angle than the airplane
     airplaneangley= transform.eulerAngles.y; 

// Maincode flying ----------------------------------------------------------------------------------------------------------------------------------

 //  Code is active when varwhatmoves is 1
 if(gameover==0){

 //  Rotations of the airplane
     if (speed>595)transform.Rotate(Input.GetAxis("Vertical")*Time.deltaTime*100,0,0); // Up Down, limited to a minimum speed
     transform.Rotate(0,Input.GetAxis("Horizontal")*Time.deltaTime*100,0,Space.World); // Left Right
     if (groundtrigger.triggered==0) transform.Rotate(0,0,Input.GetAxis("Horizontal")*Time.deltaTime*50*-1); // Tilt multiplied with minus 1 to go into the right direction
     
     //limit tilt so that airplane doesn`t fly a roll while flying a curve
     if ((Input.GetAxis ("Horizontal")<0)&&(rotationz >45)&&(rotationz <90)) transform.Rotate(0,0,Time.deltaTime*-50);// the left
     if ((Input.GetAxis ("Horizontal")>0)&&(rotationz <315)&&(rotationz >270)) transform.Rotate(0,0,Time.deltaTime*50);// the right

 // Speed
     transform.Translate(0,0,speed/20*Time.deltaTime);
 
 
 // Turn variables to rotation and position of the object
     rotationx=transform.eulerAngles.x; 
     rotationy=transform.eulerAngles.y; 
     rotationz=transform.eulerAngles.z; 
     positionx=transform.position.x;
     positiony=transform.position.y;
     positionz=transform.position.z;

 
 //Rotate back in z axis , limited by no horizontal button pressed
     if ((rotationz >0) && (rotationz < 90)&&(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*-50);
     if ((rotationz >0) && (rotationz > 270)&&(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*50);
     if ((rotationz >180) && (rotationz < 270)&&(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*-50);
     if ((rotationz <180) && (rotationz > 90)&&(!Input.GetButton ("Horizontal"))) transform.Rotate(0,0,Time.deltaTime*50);
     
     // Rotate back X axis
     
             if ((rotationx >0) && (rotationx < 180)&&(!Input.GetButton ("Vertical"))) transform.Rotate(Time.deltaTime*-50,0,0);
             if ((rotationx >0) && (rotationx > 180)&&(!Input.GetButton ("Vertical"))) transform.Rotate(Time.deltaTime*50,0,0);
     
     
     //Speed driving and flying ------------------------------------------------------------------------------------------
     
     //We need a minimum speed limit in the air. We limit again with the groundtrigger.triggered variable
 
     // Input Accellerate and deccellerate at ground
     if ((groundtrigger.triggered==1)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
     if ((groundtrigger.triggered==1)&&(Input.GetButton("Fire2"))&&(speed>0)) speed-=Time.deltaTime*240;
     
             // Input Gas geben und abbremsen in der Luft|| Input Accellerate and deccellerate in the air
     if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire1"))&&(speed<800)) speed+=Time.deltaTime*240;
     if ((groundtrigger.triggered==0)&&(Input.GetButton("Fire2"))&&(speed>600)) speed-=Time.deltaTime*240;
     
     
     //When we don`t accellerate or deccellerate we want to go to a neutral speed in the air. With this speed it has to stay at a neutral height. Above this value the airplane has to climb, with a lower speed it has to  sink. That way we are able to takeoff and land then.
     
         // Neutral speed at 700
         // Maximum 800, minimum 600
         //This code resets the speed to 700 when there is no acceleration or deccelleration. Maximum 800, minimum 600
     if((Input.GetButton("Fire1")==false)&&(Input.GetButton("Fire2")==false)&&(speed>595)&&(speed<700)) speed+=Time.deltaTime*240;
     if((Input.GetButton("Fire1")==false)&&(Input.GetButton("Fire2")==false)&&(speed>595)&&(speed>700)) speed-=Time.deltaTime*240;
 
     

     transform.Translate(0,uplift*Time.deltaTime/10.0,0);
             
     // Calculate uplift
     uplift = -700+speed;

//We don`t want downlift. So when the uplift value lower zero we set it to 0 if ((groundtrigger.triggered==1)&&(uplift < 0)) uplift=0; } }

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Multiple Animations, Please Help 1 Answer

how to change default third player controls in unity, to work with touch? 1 Answer

Help with eval() 0 Answers

How do I make the scrolling texture background change direction depending on keyboard input for the player movement controls? 3 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