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 LCK6180G · Jan 23, 2017 at 01:09 PM · unity 5scripting problemunity5collision detectionscriptingproblem

where have i went wrong in my script (unity 5)

hello, im trying to make a script for a simple flight control using torques (as im not aiming realism) and as this is unity 5 im super confused with what i'm doing since most of the scripts and guides i use might be older and is designed for unity 4, there is just some things i cant find an answer to make it work or atleast compile in my script, maybe someone could help me here

 #pragma strict
 
 public var pitch : float = 35f;
 public var bank : float =12f;
 public var yaw : float =3f;
 public var gturn : float =3f;
 
 
 
 //speed is more like thrust it seems, but meh too lazy to change any
     var speed : float;
     var speedincrease : float;
     var speeddecrease : float;
     var Maxspeed : int;
     var Minspeed : int;
     var Obj : Rigidbody;
 //for ground/air control (confused to where to put it)
     var taxi : GameObject;
     var rway : GameObject;
     var gnd : GameObject;
 
 
 function Start () {
 
     InvokeRepeating("Speed", .1, .1);
 }
 
 
 //taxi control (if it works -which doesnt)
 function OnCollisionEnter (col : Collision)
 {
 //aileron
     if (col.gameObject.name == var taxi )//use for the taxiway
     {
     if (Input.GetKey("right")){
     GetComponent.<Rigidbody>().AddTorque(-transform.forward * gturn );
     }
     if (Input.GetKey("left")){
     GetComponent.<Rigidbody>().AddTorque(transform.forward * gturn );
     }
 
 //rudder
     if (Input.GetKey("z")){
     GetComponent.<Rigidbody>().AddTorque(-transform.up * gturn );
     }
     if (Input.GetKey("c")){
     GetComponent.<Rigidbody>().AddTorque(transform.up * gturn );
     }
     }
 }
 
 //runway control (works only on runway, elevator should deploy at "certain" speed not implemented yet because im confused)
 function OnCollisionEnter (col : Collision)
 {
 //aileron
     if (col.gameObject.name == var rwar )//use for the runway
     {
     if (Input.GetKey("right")){
     GetComponent.<Rigidbody>().AddTorque(-transform.forward * gturn );
     }
     if (Input.GetKey("left")){
     GetComponent.<Rigidbody>().AddTorque(transform.forward * gturn );
     }
 //rudder
     if (Input.GetKey("z")){
     GetComponent.<Rigidbody>().AddTorque(-transform.up * gturn );
     }
     if (Input.GetKey("c")){
     GetComponent.<Rigidbody>().AddTorque(transform.up * gturn );
     }
 //elevators
     if (Input.GetKey("down")){
     GetComponent.<Rigidbody>().AddTorque(-transform.right * pitch );
     }
     if (Input.GetKey("up")){
     GetComponent.<Rigidbody>().AddTorque(transform.right* pitch );
     }
     }
 }
 //air control (if it works -which doesnt)
 function OnCollisionExit (col : Collision)//not colliding with the 2 object, aka taxi and runway to work
 {
 //elevators
     if (Input.GetKey("down")){
     GetComponent.<Rigidbody>().AddTorque(-transform.right * pitch );
     }
     if (Input.GetKey("up")){
     GetComponent.<Rigidbody>().AddTorque(transform.right* pitch );
     }
 //ailerons
     if (Input.GetKey("right")){
     GetComponent.<Rigidbody>().AddTorque(-transform.forward * bank );
     }
     if (Input.GetKey("left")){
     GetComponent.<Rigidbody>().AddTorque(transform.forward * bank );
     }
 //rudder
     if (Input.GetKey("z")){
     GetComponent.<Rigidbody>().AddTorque(-transform.up * yaw );
     }
     if (Input.GetKey("c")){
     GetComponent.<Rigidbody>().AddTorque(transform.up * yaw );
     }
 }
 //ends here currently, also placeholder and space, my head's steaming
    
 
 //something's missing here: speed limiter and speed=heading not momentum along with the speedo
 function Speed (){
 
 if (Input.GetKey("q")){
 Mathf.Repeat(1,Time.time);
     speed=speed+speedincrease;
     }
 if (Input.GetKey("a")){
 Mathf.Repeat(1,Time.time);
     speed=speed-speeddecrease;
     }
 }
 function Update () {
 
 var spd = Obj.velocity.magnitude;
 
     Obj.GetComponent.<Rigidbody>().AddRelativeForce(0,0,speed);
 
     if(Maxspeed<=speed){
     speed=Maxspeed;
     }else{
     speed=speed;
     }
     if(Minspeed>=speed){
     speed=Minspeed;
     }else{
     speed=speed;
     }
 }
 //currently end of the line, either i mix all the scripts or mix em in one big bag of mess
 
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Script sets same value to other script in all objects instead of just one. 1 Answer

Collider with rigidbody does not register collision with terrain 2 Answers

Reference DLL's 1 Answer

Raycast do not detect when distance is closer or further than the max distance 1 Answer

Refresh panel with prefab contained value from json that created using array 0 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