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 /
  • Help Room /
avatar image
0
Question by Jakeoteph · Sep 29, 2017 at 03:39 AM · physicscoroutineacceleration

Do I need a Coroutine to handle acceleration?

I started working on what I thought would be very simple space shooter over 6 months ago and while I have come very far, one thing has eluded me and that has been the ship controls. I'm not certain what I am doing wrong and I have no hair left to tear out. I've tried dozens of tutorials and cant quite get what I want. I'm creating a top-down space shooter in 3D and despite the numerous tutorials, I cant find any that cover what i need. I want to make a ship that accelerates towards a top speed when the up key is pressed and I want the ship to continue its currents trajectory if the key is released maintaining its current speed even if it has not met the top speed. I would like the down key to pull back on the ship like brakes/reverse until a maximum deceleration is met and once again maintaining a current speed if the key is released. I don't know what I need for this, maybe a Coroutine?

 {
     public float turnSpeed = 50f;
 
     public float _Velocity = 0.0f;      // Current Travelling Velocity
     public float _MaxVelocity = 1.0f;   // Maxima Velocity
     public float _Acc = 0.0f;           // Current Acceleration
     public float _AccSpeed = 0.1f;      // Amount to increase Acceleration with.
     public float _MaxAcc = 1.0f;        // Max Acceleration
     public float _MinAcc = -1.0f;       // Min Acceleration
 
 
     void Update()
     {
 
         if (Input.GetKey(KeyCode.UpArrow))
             _Acc += _AccSpeed;
 
         if (Input.GetKey(KeyCode.DownArrow))
             _Acc -= _AccSpeed;
 
         if (Input.GetKey(KeyCode.LeftArrow))
             transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
 
         if (Input.GetKey(KeyCode.RightArrow))
             transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
 
 
         if (_Acc > _MaxAcc)
             _Acc = _MaxAcc;
         else if (_Acc < _MinAcc)
             _Acc = _MinAcc;
 
         _Velocity += _Acc;
 
         if (_Velocity > _MaxVelocity)
             _Velocity = _MaxVelocity;
         else if (_Velocity < -_MaxVelocity)
             _Velocity = -_MaxVelocity;
 
         transform.Translate(Vector3.forward * _Velocity * Time.deltaTime);
     }
 }`
 

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

166 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hovercar rigidbody acceleration 1 Answer

in projectiles, how to equate horizontal speed as function of Horizontal displacement(how far I want the object to travel sideways) 0 Answers

Order of execution: AddForce, rigidbody movement, velocity update? 0 Answers

Help and ideas for decent physics of a row boat 1 Answer

How to make Airplane move forward faster INSTANTANEOUSLY? 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