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
7
Question by anuvk · Feb 28, 2014 at 06:52 AM · velocitydragformula

How drag is calculated by Unity engine.?

Hi all,

Do anyone know, how Unity Engine calculates drag for rigidbody which is applied by a force.

I have car and set drag as 0.35 in rigidbody setting. Is that calculated proportional to the velocity, if so could you share the formulae used.?

Is it DragForce = DragCoefficient * Velocity .?

Please help me.

Regards, anu

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
11

Answer by yavilevich · Dec 06, 2015 at 02:52 PM

Based on what I have tested, though in real physics, drag is calculated as

  dragForceMagnitude = velocity.magnitude ^ 2 * drag;

in Unity a linear approximation is used. Where on each FixedUpdate

  velocity = velocity * ( 1 - deltaTime * drag);

This is based on the following forum posts: http://forum.unity3d.com/threads/drag-factor-what-is-it.85504/ and http://forum.unity3d.com/threads/physics-drag-formula.252406/

So the change on velocity at each FixedUpdate is

 vNEW = (v+a*dt)*(1-drag*dt)
 f = m*a

The result of this is that, given some constant force, an object with drag will reach a certain max velocity (vNEW=v). The calculation of the formula of such velocity (vSaturation) is included below.

we will assign v=vSAT and vNEW=vSAT and get:

 vSAT = (vSAT+a*dt)*(1-drag*dt)
 vSAT*drag*dt = a*dt - a*drag*dt^2
 vSAT*drag = a - a*drag*dt
 vSAT = a/drag - a*dt = f/m/drag - a*dt

so if force is 100, mass is 1, drag is 1 and dt=1/50 we get

 vSAT = 100/1 - 100/50 = 98
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 TonicMind · Jun 11, 2017 at 06:20 PM 0
Share

$$anonymous$$ight I ask why you have the equation

    velocity = velocity * ( 1 - deltaTime * drag);

When in this link (you linked to) its called acceleration?

https://forum.unity3d.com/threads/physics-drag-formula.252406/

Don't get me wrong, I think you're correct because in Nickdas' physics script he applies acceleration to the position of the object which sounds incorrect to me. I think so because in any other equation I've found to find velocity it is

v(t) = v + a*dt

The last thing I wanted to ask is probably pretty simple but I am unsure. Is 'a' dependent on 't' or is 'v'?

avatar image
2

Answer by CodeElemental · Feb 28, 2014 at 12:49 PM

Drag affects the object's velocity , approximately with the formula :

 dragForceMagnitude = velocity.magnitude ^ 2 * drag;
 dragForceVector = dragForceMagnitude * -velocity.normalized;

If you want to know more , visit the forums , from where i actually got the info.

Also , you can maybe find this table for drag coeff for primitives usefull.

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 RicBrasil · Feb 19, 2021 at 07:58 PM

Hi guys, I ran into this problem and looked it up for a solution. And didn't find one on unity space equation. Basically I needed to launch an projectile to certain point in space given the time "t". It also works for 3D if you use Vector3. In my case I'm simulating wind by changing the component x of the gravity. So I end up finding in a physics site about linear drag. And I came up with this:

 Vector2 a = Physics2D.gravity * shotRigibody.gravityScale;
                 Vector2 deltaS = (Vector2)(_target.position - shotInstance.transform.position);
                 float t = 2f;
                 if (rigibody.drag > 0)
                 {
                     float drag = rigibody.drag;
                     float tMax = 1 / drag;
                     float et = Mathf.Exp(-t / tMax);
                     Vector2 vt = a / drag;
                     rigibody.velocity = (deltaS - vt * t - vt * tMax * (et - 1)) / (tMax * (1 - et));
                 }
                 else
                 {
                     rigibody.velocity = (deltaS - a*t*t /2 )/ t;
                 }
 


This physics site uses F = m*g - b*v while unity uses F = m*g - m*drag*v. So you can replace b for drag*m.

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

26 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

Related Questions

Horizontal Drag, no Vertical Drag 1 Answer

Limiting the top speed of a rigidbody in 3d space? 1 Answer

Why is there still drag when drag is 0? 0 Answers

Velocity Formula 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 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