TL;DR
How to apply some force to a rigidbody with some random drag value, so that the velocity of the rigidbody is the same, independently of what the drag value is?
So i have some rigidbodies, and a force field that is pushing them in some direction. What i need, is that their speed when they are being pushed to be the same. The problem here is that rigidbodies have different Linear Drag values.
So to compensate for the drag, i must apply different forces to rigidbodies depending on their drag value. But i can’t find any formula where it says how drag is related to velocity of the body.
I have found this thread, and the formula for drag is claimed to be something like this:
float coeff = (1 - Time.deltaTime * rigidbody.drag);
which does not work, since for drag values enough high (which is my case, its 55 for some objects), i get a negative coefficient, which is not correct.
I use it like this:
var dragCoeff = 1f + Time.deltaTime * target.CachedRigidbody2D.drag;//we need to eliminate drag
var power = dir.normalized * Power * Time.deltaTime;
target.CachedRigidbody2D.AddForce(power.ToVector2() / dragCoeff, Mode);
where
- dir - the direction of the force that will be applied
- Power - is the power of the force
- target - the object to which the force will be applied
- Mode - is the force mode, ForceMode2D.Force is used in this case.
and when the coefficient is negative, the object is being pushed in the wrong direction.
Any solution? how is drag related to velocity?
I need a function that depends on drag that will give me the needed force to apply to the object so that it would compensate for the drag, any hint is appreciated.