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
3
Question by roburky · Aug 02, 2011 at 02:37 PM · physicsrigidbodyspeedprediction

Calculating rigidbody top speed?

If I am applying a force to a rigidbody each FixedUpdate, is it possible to calculate or predict the maximum speed it will be able to reach?

It feels like there ought to be some calculation I can do using the force.magnitude, rigidbody.drag, rigidbody.mass, and probably Time.fixedDeltaTime. But I'm not sure what it is.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Jonatan Crafoord · Oct 05, 2012 at 12:36 PM

EDIT: After writing a long post about my own failed attempts at this I found the following forum post which accurately describes how to calculate Terminal Velocity: http://forum.unity3d.com/threads/34667-Terminal-Velocity

From that I derived the following calculation:

 float topVelocity = ((addedForce.magnitude / rigidbody.drag) - Time.fixedDeltaTime * addedForce.magnitude) / rigidbody.mass;

Below is my old post, kept for reference but not very useful I suspect.


I would very much like to know this as well! This is how far I've got, maybe we can solve the problem together?

I also figured that the top velocity must be a function of the drag, the force you add and the mass. By setting mass = 1 or using ForceMode.Acceleration we can just ignore the mass for now.

I found a note on how PhysX calculates the drag force. Apparently it uses the following calculation:

dragForceMagnitude = velocity.magnitude ^ 2 drag*

The top speed should be when the dragForceMagnitude is equal to the magnitude of whatever force we are adding. When this happens, the drag vector balances out the added force. The rigidbody does not speed up or slow down, i.e. max velocity is achieved.

The forces must also use the same time measurement of course, which makes it a bit tricky as rigidbody velocity is in units per second and we're likely adding forces each FixedUpdate.

Anyway, the calculation should look roughly like this:

topSpeed = velocity.magnitude when dragForceMagnitude = addedForce.magnitude

So, trying to solve this, I inserted the PhysX calculation in the equation, getting this:

velocity.magnitude ^ 2 drag = addedForce.magnitude*

or, since topSpeed and velocity.magnitude is the same when this happens:

topSpeed ^ 2 drag = addedForce.magnitude*

Solving the equation for topSpeed, we get:

topSpeed = Sqrt(addedForce.magnitude / drag)

In Unity, using C#, the code would then look like this:

 // The force you add each FixedUpdate using ForceMode.Acceleration or ForceMode.Force with mass 1
 Vector3 addedForce; 
 
 // The top speed in units per second
 float topSpeed;
 
 // The equation
 topSpeed = Mathf.Sqrt((addedForce.magnitude) / rigidbody.drag) / Time.fixedDeltaTime;

However, when I print this calculation the values I get are obviously incorrect. Doing a measurement, I found that for a drag value of 0.2, the object claimed a top speed that was 3.31 times as high as the speed it had when it was no longer accelerating. For a drag value of 0.5, the claimed top speed was 2.08 times the achieved top speed, so not even the same difference.

I suspect my error is somewhere in how I convert the added force per frame to units per second. It may also be some other mathematical error. Or, the PhysX calculation may simply be incorrect or outdated. :(

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
0

Answer by Nialit · Mar 12, 2013 at 09:06 PM

Hi! The formula of top phys speed, calculated from drag and force applied(in case of Force.Acceleration) is the next(my own research): topspeed = (rigidbody.drag*appliedspeed)/(1-0.01f*rigidbody.drag);

So, you can use Vector3 instead appliedspeed, and use it inside AddForce; Good luck!

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
0

Answer by Cameron_SM · Dec 02, 2014 at 09:14 AM

Unity seems to have a bug, rigidbody applies a basic stokes drag but does so after applying forces to the velocity so the velocity at the time of caculating the drag is actually incorrect (I've tested this, a lot, see my reply to the thread here for full explination: http://forum.unity3d.com/threads/terminal-velocity.34667/).

The workaround is to calculate the drag yourself and apply it directly, don't use the drag property of a rigidbody component as it's not applied correctly:

 // a = acceleration, forward = transform.forward, dt = fixedDeltaTime
 var drag = a / maxSpeed;
 rigidbody.velocity += ((forward * a) - (rigidbody.velocity * drag)) * dt;

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

6 People are following this question.

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

Related Questions

Add velocity relative to ground? 1 Answer

Predicting land position with drag applied 0 Answers

Rigidbody gain speed falling on slope 0 Answers

Turn-based vehicle physics 1 Answer

Predicting A Trajectory 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