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 Flanker37T · Jun 10, 2016 at 12:09 PM · rigidbody2d2d-physicsaccelerationsmoothingaircraft

How to smooth (slow down) aircraft acceleration (Rigidbody2D)?

Greetings! I spent last week or so trying to resolve an issue, and did not succeed. In my game, I use physics (Rigidbody2D) and addForce to accelerate the aircraft. The force added is proportional to thrust.

The problem is as follows: if I add a lot of force, I reach realistically high speeds unrealistically quickly. If I add less force, I have realistic acceleration, but snails' top speed. I tried to play with drag, but the equation evens itself out: twice less force with twice less drag produce same acceleration and top speed. Increasing mass slows acceleration, but proportionally reduces max speed.

What I am doing now is having several drag equations depending on player's speed to limit the acceleration down to manageable levels, but it feels very clunky (not to mention unintuitive and unrealistic).

Here are snippets of my code:

  //////////////////Adding thrust/////////////////////////////
 rb.AddForce(transform.right*thrust); //thrust goes from 0 to 100

 //////////////////Drag equations/////////////////////////////
     if (rb.velocity.magnitude <= 3)
           rb.drag = Mathf.Clamp(-rb.velocity.magnitude / 8f + 4f, 2.1f, 4f);
     else if (rb.velocity.magnitude <= 4)
           rb.drag = Mathf.Clamp(-rb.velocity.magnitude / 4.9f + 4f, 2.1f, 4f);
     else if (rb.velocity.magnitude <= 7) 
           rb.drag = Mathf.Clamp(-rb.velocity.magnitude / 2.9f + 4.15f, 1.1f, 4f);
     else if (rb.velocity.magnitude <= 10)
           rb.drag = Mathf.Clamp(-rb.velocity.magnitude / 5f + 3.2f, 1f, 4f);
     else
           rb.drag = Mathf.Clamp(-rb.velocity.magnitude / 18f + 1.7f, 0.8f, 4f);

Speed conversion from units to km/h is as follows:

 speedText.text = "Speed: " + Mathf.Round(rb.velocity.magnitude * 50 * 3.6f) + "km/h";

So rb.velocity.magnitude of 7 is 1260 km/h.

Without my drag equations the craft either boosts to 2500km/h almost instantly, or slowly accelerates to 500km/h and stays there. Am I missing something? How can I have high top speed AND slow acceleration?

Thanks in advance.

Update: If it is impossible, I would also like to know that. Although I doubt it - KSP has (moderately) realistic acceleration based on mass, drag and force, and KSP is made in Unity.

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

2 Replies

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

Answer by Flanker37T · Jun 28, 2016 at 04:52 AM

So I decided to stick with drag equations and found a "sigmoid" function, which is absolutely perfect for this case. After an hour or so of tinkering, I found the shape which works great for me (maybe it'll help somebody with a similar problem): 6/(1+e^(0.18(x-0.5)))+0.35., where x is rigidbody.velocity.magnitude.

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

Answer by ryanmillerca · Jun 14, 2016 at 09:37 PM

You might find the velocity change approach in the Unify Wiki's "Rigidbody FPS Walker" helpful, as it tackles a similar issue.

http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker

Comment
Add comment · Show 1 · 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
avatar image Flanker37T · Jun 14, 2016 at 11:42 PM 0
Share

Thank you! I've played with that solution for a bit, but in the end stumbled upon the same wall. Here is what I added:

 changeInVel = $$anonymous$$athf.Clamp(maxSpeed - rb.velocity.magnitude, 0, maxAccel);
 rb.AddForce(transform.right*changeInVel*thrust);

But the problem is that if I set maxAccel to 1 (to get smooth acceleration), the object accelerates to a speed of ~13 (2350km/h), and then gets stuck due to drag (so setting max speed to anything higher than 13 is pointless), which is the exact same problem I started with. If I reduce drag, speed increases, but so does the acceleration. To counter this, I set lower acceleration, which again lowers speed. It's a cursed circle.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Simulating weight on RigidBody2D objects? 0 Answers

determining angular acceleration. Is this possible, and if so how to do this? 0 Answers

Rigidybody2D addforce at constant speed 1 Answer

How to rotate rigidbody2d's sprite when colliding?,How to rotate sprite of rigidbody2d, but without friction? 0 Answers

How to select the trigger layer on a Box Collider 2D 2 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