What units of measurement does Unity use for velocity and drag? I'm guessing meters/second by I just want to be 100%.
Thank you.
What units of measurement does Unity use for velocity and drag? I'm guessing meters/second by I just want to be 100%.
Thank you.
The units for velocity is world units per second, as Jessy said.
The unit for drag is a little weird. It is “per second” (or inverse seconds). This is from a calculation (after some experimentation) done by my friend. He found that
Drag Constant = -Drag Acceleration / Object Velocity
with the mass of the object not affecting the acceleration.
As the units for acceleration are meters/second^2 (lets just call world units meters) and velocity is meters/second, the meters and one of the seconds cancel, leaving us with 1/second or “per second”.
P.S. Of course, without access to Unity’s code or a confirmation from a Unity employee, the exact implementation might not be this.
P.P.S. I know that I bumped this (just) year old question; I ran into this conundrum as well and I figured that others might want to know too.
World units per second.
I recently had to touch on Physics, and as I stumbled upon this very same question, I decided to do a little bit of experiment.
To properly understand how drag works, I decided to recreate it with a custom component.
I’ve come to the conclusion that drag applies a counter force equal to the expected velocity increase over the next fixedDeltaTime.
To do this, it sums the current velocity plus all forces applied within current FixedUpdate, and applies an opposite force.
It’s like doing the following :
void FixedUpdate ()
{
// countering gravity if the rigidbody's using it
if (rigidBody.useGravity)
rigidBody.AddForce(-Physics.gravity * Time.fixedDeltaTime * drag, ForceMode.Acceleration);
// countering constant force if present
if (_useConstantForce)
rigidBody.AddForce(-(_constantForce.force + transform.TransformVector(_constantForce.relativeForce)) * Time.fixedDeltaTime * drag, ForceMode.Force);
// countering current velocity
rigidBody.AddForce(-rigidBody.velocity * drag, ForceMode.Acceleration);
}
public void AddForce (Vector3 force, ForceMode mode = ForceMode.Force)
{
rigidBody.AddForce (force - force * drag * Time.fixedDeltaTime, mode);
}
public void AddRelativeForce (Vector3 force, ForceMode mode = ForceMode.Force)
{
rigidBody.AddRelativeForce (force - force * drag * Time.fixedDeltaTime, mode);
}
General rules of thumb :
Hope this helps.