• 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
Question by $$anonymous$$ · Jul 22, 2010 at 01:34 PM · controllerairplane

Airplane controller problem

Hello everyone, my problem is this: I am using the following code as a control for my airplane, and works very well as I wanted, but when the plane collides with some object with a helper collider, the plane lost control. Anybody know how can I fix this?

alt text

var DiamondSound : AudioClip; static var money = 0;

static var airplaneangley: float=0.0;

static var rotationx:float =0.0; static var rotationy:float =0.0; static var rotationz:float =0.0; var positionx: float=0.0; static var positiony: float=0.0; var positionz: float=0.0;

static var speed:float =15.0; var uplift:float =0.0;

var rightleftsoft:float=0.0; // Variable for soft curveflight var rightleftsoftabs:float=0.0; // Positive rightleftsoft Variable

var divesalto:float =0.0; // blocks the forward salto var diveblocker:float=0.0; // blocks sideways stagger flight while dive

function OnTriggerEnter (other : Collider) { if (other.gameObject.tag == "diamonds") { money+=1; audio.clip = DiamondSound; audio.Play(); Destroy(other.gameObject); }

}

function Update () {

airplaneangley= transform.eulerAngles.y;

rotationx=transform.eulerAngles.x; rotationy=transform.eulerAngles.y; rotationz=transform.eulerAngles.z; positionx=transform.position.x;

positiony=transform.position.y; positionz=transform.position.z;

if ((Input.GetAxis("Vertical")<=0)) { transform.Rotate((Input.GetAxis("Vertical")*Time.deltaTime*80),0,0); }

if ((Input.GetAxis("Vertical")>0)){ transform.Rotate((Input.GetAxis("Vertical")*Time.deltaTime*80),0,0); }

if (speed>0) transform.Rotate(0,Time.deltaTime*100*rightleftsoft,0,Space.World);

if (speed>0) transform.Rotate(0,0,Time.deltaTime*100*(1.0-rightleftsoftabs-diveblocker)Input.GetAxis("Horizontal")-1.0);

if ((Input.GetAxis ("Horizontal")<0)&&(rotationz >0)&&(rotationz <90)) rightleftsoft=rotationz*2.2/100*-1;// to the left if ((Input.GetAxis ("Horizontal")>0)&&(rotationz >270)) rightleftsoft=(7.92-rotationz*2.2/100);//to the right

if (rightleftsoft>1) rightleftsoft =1; if (rightleftsoft<-1) rightleftsoft =-1;

if ((rightleftsoft>-0.01) && (rightleftsoft<0.01)) rightleftsoft=0.0;

rightleftsoftabs=Mathf.Abs(rightleftsoft);

if (rotationx < 90) divesalto=rotationx/10.0;//Updown if (rotationx > 90) divesalto=rotationx/-10.0;//Updown

if (rotationx <90) diveblocker=rotationx/200.0; else diveblocker=0;

if ((rotationz <90)&&(Input.GetAxis ("Horizontal")>0)) transform.Rotate(0,0,rightleftsoft*Time.deltaTime*80); if ((rotationz >90)&&(Input.GetAxis ("Horizontal")<0)) transform.Rotate(0,0,rightleftsoft*Time.deltaTime*80);

if (!Input.GetButton ("Horizontal")){ if ((rotationz < 135)) transform.Rotate(0,0,rightleftsoftabs*Time.deltaTime*-100); if ((rotationz > 225)) transform.Rotate(0,0,rightleftsoftabs*Time.deltaTime*100); }

if ((!Input.GetButton ("Vertical"))&&(groundtrigger.triggered==0)){ if ((rotationx >0)&&(rotationx < 180)) transform.Rotate(Time.deltaTime*-1,0,0); if ((rotationx >0)&&(rotationx > 180)) transform.Rotate(Time.deltaTime*1,0,0); } transform.Translate(0,0,speed*Time.deltaTime);

}

Comment
Thom Denick

People who like this

1 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by jesseoffy · Aug 17, 2010 at 07:29 PM

I loaded the script and got the error that I had no groundtrigger, so I deleted that part at the end so the line only read: if((!Input.GetButton ("Vertical"))) {

I don't know what you mean - it goes out of control... I attached it to an empty game object. This game object held both my camera and a cylinder with a character collider (my fake airplane). The script worked pretty well, except every now and then, when I turned, I got some weird camera jiggle - But when I hit a surface (one was a cube and another a plane) my cylinder airplane didn't lose control - it just sorta bumped of and kept flying.

Comment

People who like this

0 Show 0 · 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

No one has followed this question yet.

Related Questions

MMD How to export model and animations to Unity as 3rd person controller? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Airplane controller for game object? 0 Answers

Aircraft controller script 2 Answers

Not able to jump when running!Where did I go wrong? 1 Answer


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