How drag is calculated by Unity engine.?
Asked Answered
R

4

0

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

Ruff answered 19/10, 2023 at 14:23 Comment(0)
D
0

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.

Drip answered 6/6, 2023 at 2:38 Comment(0)
U
0

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
Unalienable answered 19/10, 2023 at 14:23 Comment(1)

Might 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'?

Shriek
L
0

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 = mg - bv while unity uses F = mg - mdragv. So you can replace b for dragm.

Lingerfelt answered 19/10, 2023 at 14:29 Comment(0)
U
0

Hi. For anyone here looking specifically for maximum velocity a body can reach with given mass, acceleration force & drag, here’s the formula:

a = acceleration force / mass
vSAT = a / drag

It’s delta time independent. It works for me in 2022.3.10f1

Urbanity answered 6/12, 2023 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.