Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Tim-A · Nov 21, 2012 at 02:28 AM · javascriptspeedplaneincreaseslowly

Plane increase speed

OK, I have a plane script that works just fine. I need it to slowly increase speed just like a real plane. The way it is written just shoots it off.

 var moveSpeed= 60.0;
 
 
 
 var turnSpeed = 40.0;
 
 
 
 var Forward : KeyCode;
 
 
 
 var Backward : KeyCode;
 
 
 
 var Left : KeyCode;
 
 
 
 var Right : KeyCode;
 
 
 
 function Update () {
 
 
 
 if(Input.GetKey(Forward))
 
 
 
 {
 
        transform.eulerAngles.z += - turnSpeed * Time.deltaTime;
 
     }
 
 
 
  if(Input.GetKey(Backward))
 
     {
 
 
 
  transform.eulerAngles.z += turnSpeed * Time.deltaTime;
 
     }
 
 
 
     if(Input.GetKey(Left))
 
     {
 
        transform.eulerAngles.x +=  turnSpeed * Time.deltaTime;
 
     }
 
     if(Input.GetKey(Right))
 
     {
 
        transform.eulerAngles.x += - turnSpeed * Time.deltaTime;
 
     }
 
 
 
     if(Input.GetButton("Jump")){
 
        transform.position += transform.right * - moveSpeed * Time.deltaTime;
 
     }
 
 
 
 }




Any help would be appreciated.

                                 Thanks, Tim

alt text

plane.png (37.8 kB)
Comment
Add comment · Show 11
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 sparkzbarca · Nov 21, 2012 at 02:44 AM 0
Share

are you using a character controller, a kinematic rigidbody or a rigidbody.

it APPEARS based on the inclusion of Jump code (for a plane :P) your using the included charactercontroller.

Would you like an arcade style aircraft or a realistic physics simulation of the plane?

realistic physics requires a rigidbody aircraft.

A charactercontroller is fine for an arcade style flight simulation.

avatar image Tim-A · Nov 21, 2012 at 02:58 AM 0
Share

I think I am using a rigidbody. I would like a simulation style though.

avatar image sparkzbarca · Nov 21, 2012 at 03:05 AM 0
Share

well your not using a rigidbody with that code. :P

rigidbodies apply forces to move objects they dont move them directly

what your doing is teleporting the object around basically.

Ridigbodies use the nvidia physix engine to calculate movement.

for a rigidbody you would add the rigidbody component to the plane and use

plane.rigidbody.addforce(vector3 force);

it will add force in the direction vector3

if you would like it to add forward momentum use

plane.rigidbody.addforce(plane.transform.forward * speed)

it will build on itself so if you add 10 meters per second it will grow by 10 meters per second per second until you stop adding force.

as such it will be

1st second 10m per s 2nd second 20m per s 3rd second 30m per s

except physics calculations will kick in and based on the drag coefficient you set in the rigidbody options the object will have a negative force applying on in the opposite direction trying to stop it as well as gravity pushing it down.

avatar image Tim-A · Nov 21, 2012 at 03:13 AM 0
Share

I added a picture just saying. And saying plane.transform would do an error right.

avatar image Tim-A · Nov 21, 2012 at 03:15 AM 0
Share

So, this would be the new code?
var moveSpeed= 60.0; var turnSpeed = 40.0; var Forward : $$anonymous$$eyCode; var Backward : $$anonymous$$eyCode; var Left : $$anonymous$$eyCode; var Right : $$anonymous$$eyCode; var plane :GameObject; function Update () { if(Input.Get$$anonymous$$ey(Forward)) { transform.eulerAngles.z += - turnSpeed Time.deltaTime; } if(Input.Get$$anonymous$$ey(Backward)) { transform.eulerAngles.z += turnSpeed Time.deltaTime; }

     if(Input.Get$$anonymous$$ey(Left))
     {
        transform.eulerAngles.x +=  turnSpeed * Time.deltaTime;
     }
     if(Input.Get$$anonymous$$ey(Right))
     {
        transform.eulerAngles.x += - turnSpeed * Time.deltaTime;
     }
 
     if(Input.GetButton("Jump")){
        plane.rigidbody.addforce(plane.transform.forward * moveSpeed);
     }
 
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MountDoomTeam · Nov 27, 2012 at 02:54 PM

Hello, did you see there is a code formatting button at the top of the post page

 if ( Input.GetKey("mouse 1") )
  {constantForce.relativeForce = 15000 * Vector3.forward
 ;}

this simulates thrusters on a plane by adding a constant force forwards

Here is the complete code for my plane:

 var speed = 15.0;
 var rotspd = 10.0 ;
 var bullitPrefab : Transform;
 
 
 function Update ()
 { 
 
 
 if ( Input.GetKey("mouse 1") )
  {constantForce.relativeForce = 15000 * Vector3.forward
 ;}
 else 
  {constantForce.relativeForce = Vector3.zero;}
     if(Input.GetButton("forwards"))
      { 
               transform.eulerAngles.x += rotspd * Time.deltaTime * 7;
      }             
      
           if(Input.GetButton("backwards"))
      { 
               transform.eulerAngles.x += -rotspd * Time.deltaTime * 7;
      }        
      
           if(Input.GetButton("left"))
     {
               transform.eulerAngles.y += -rotspd * Time.deltaTime * 7;
      }        
      
           if(Input.GetButton("right"))
      { 
              transform.eulerAngles.y += rotspd * Time.deltaTime * 7;
      }        
 
     
         if(Input.GetButton("Fire1")) 
       { 
      var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
       bullit.rigidbody.AddForce(transform.forward *8000);
      }
       
 }     
 
 /*var speed = 3.0;
 
 var rotateSpeed = 32.0;
 
 var bullitPrefab : Transform;
 
 function Update ()
 { 
     var controller : CharacterController=GetComponent(CharacterController);
     
     //Rot
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     
     //fwd bck
     var forward = transform.TransformDirection(Vector3(0,0,1));
     var curSpeed = speed * Input.GetAxis ("Vertical");
 
     controller.SimpleMove(forward * curSpeed);
 
     
     
 if(Input.GetButtonDown("Fire1")) 
       { 
       var bullit = Instantiate(bullitPrefab, transform.Find("spawnPoint").transform.position, Quaternion.identity);
       bullit.rigidbody.AddForce(transform.forward *2000);
       }
 } 
 */
 
 
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.

Follow this Question

Answers Answers and Comments

13 People are following this question.

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

Related Questions

Help with my "speeding up time" script 1 Answer

Why is C# joystick taking 300 times slower to execute then javascript Joystick? 1 Answer

Basic Movement on a Plane without Character Controller 2 Answers

Increase ball speed by time 1 Answer

fly speed , increasing speed 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