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 svist_o2 · Feb 17, 2012 at 06:46 AM · rigidbodysmoothaccelerationairplane

Airplane smooth acceleration problem

Hello! I'm new to Unity. I make a airplane, using a rigid body, the script is working correctly. But I cannot do airplane is smoothly increased from the current speed to the maximum and achieve the same slowing down (time is now or instant acceleration or deceleration). I tried to do through Rigidbody.velocity, but it does not work. I beg you with a code or advice on how to achieve a gradual acceleration and deceleration.

Thank you in advance!

Here is my script:

 var Speed = 60;
 var boostSpeed : float = 10;
 var maxSpeed = 100;
 private var Amount : Vector3 = Vector3 (10, 0, 0);    
 
 function FixedUpdate () {
 
 //Roll
 if (Input.GetKey(KeyCode.LeftArrow)) {
 rigidbody.AddRelativeTorque(Vector3.forward * 7 + Amount * Time.deltaTime);
 }
 else if (Input.GetKey(KeyCode.RightArrow))
 rigidbody.AddRelativeTorque(Vector3.back * 7 + Amount * Time.deltaTime);
 
 //Forward current speed
 transform.Translate(Vector3.forward * Time.deltaTime * Speed);
 
 //Boost-Brake <--- PROBLEM
 if (Speed < maxSpeed && Input.GetKey(KeyCode.W)) {
 rigidbody.AddRelativeForce(Vector3.forward * 70 + Amount * Time.deltaTime);
 }
 else if (Speed <= maxSpeed && Input.GetKey(KeyCode.S))
 rigidbody.AddRelativeForce(Vector3.forward * -20 + Amount * Time.deltaTime);
 
 //Yaw
 if (Input.GetKey(KeyCode.D)) {
 rigidbody.AddRelativeTorque(Vector3.up * 3 + Amount * Time.deltaTime);
 }
 else if (Input.GetKey(KeyCode.A))
 rigidbody.AddRelativeTorque(Vector3.down * 3 + Amount * Time.deltaTime);
 
 //Pitch
 if (Input.GetKey(KeyCode.UpArrow)) {
 rigidbody.AddRelativeTorque(Vector3.right * 5 + Amount * Time.deltaTime);
 }
 else if (Input.GetKey(KeyCode.DownArrow))
 rigidbody.AddRelativeTorque(Vector3.left * 5 + Amount * Time.deltaTime);
 }
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 FishBone · Feb 17, 2012 at 10:30 AM 0
Share

if deltatime is 0,01

Vector3.forward 70 + Amount Time.deltaTime = 0,0,1 70 + 10,0,0 0.01 = 0,0,70 + 0.1,0,0 = 0.1,0,70

your breaking is 0.1,0,-20

Don't know what Amount is supposed to do, but you should probably multiply the deltatime with the "Vector3.forward 70" also. (Vector3.forward 70 + Amount) * Time.deltaTime

avatar image svist_o2 · Feb 19, 2012 at 01:00 PM 0
Share

I didn't understand a bit how to do what you have written. I am new to Unity. Is so:

//Boost-Brake <--- PROBLE$$anonymous$$

if (Speed < maxSpeed && Input.Get$$anonymous$$ey($$anonymous$$eyCode.W)) {

rigidbody.AddRelativeForce((Vector3.forward 70 + Amount) Time.deltaTime); }

else if (Speed <= maxSpeed && Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))

rigidbody.AddRelativeForce((Vector3.forward -20 + Amount) Time.deltaTime);

It does not work.

I do not know how to write it?

Vector3.forward 70 + Amount Time.deltaTime = 0,0,1 70 + 10,0,0 0.01 = 0,0,70 + 0.1,0,0 = 0.1,0,70 your breaking is 0.1,0,-20

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

6 People are following this question.

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

Related Questions

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

AddTorque doesn't rotate? 3 Answers

How do I get one object to point toward another using rigidbody physics? 2 Answers

[Solved] Is it okay if we change transform.position on a kinematic rigid body which also does not use Gravity? 2 Answers

Hooking RigidBody.AddForce 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