Comments and answers for "Convert rigidbody.drag to acceleration(m/s²)?"
http://answers.unity.com/questions/1528433/convert-rigidbodydrag-to-accelerationms.html
The latest comments and answers for the question "Convert rigidbody.drag to acceleration(m/s²)?"Comment by Servail on Servail's comment
http://answers.unity.com/comments/1529158/view.html
Thank you sir, you've saved my time and nerves.Sat, 14 Jul 2018 11:23:39 GMTServailComment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1529142/view.html
No, as i said the **deceleration** is not a **constant**. It depends on the current velocity. So there is no fix relation between the drag value and the deceleration applied each frame. The drag value is constant but the deceleration is not.
<br>
Yes If you have a **constant** acceleration (like gravity) you get a **linear** velocity curve and in turn a **quadratic** position curve. However the drag force is not a constant factor as the drag force depends on the current velocity squared. So you don't have a strict relationship upwards like `acceleration --> velocity --> position` but you have a feedback of the velocity.
gravity --> velocity --> position
/|\ |
| |
drag<-/
As I've shown [over here][1] there is no formula that calculates the resulting velocity after x amount of time. This is an iterative process that can't be expressed with a single formula. There is also no formula that calculates the deceleration after x amount of frames.
<br>
Note that if you don't have gravity or any other constant accelerations you can use pow to determine the "absolute/accumulated deceleration" after x amount of frames or time.
<br>
Since you want to predict where the bullet would land there's no way around iterating your movement. You can iterate it all in a single frame. Games [like peggle][2] do all their predictions before hand by simply iterating the ball into the future to see where it would move.
[1]: https://answers.unity.com/questions/962514/calculating-trajectory-with-physx-drag.html?childToView=962581#answer-962581
[2]: https://www.youtube.com/watch?v=8joh-NT0VysSat, 14 Jul 2018 09:57:51 GMTBunny83Comment by Servail on Servail's comment
http://answers.unity.com/comments/1529062/view.html
Looks like something really close to:
deceleration = 1/(1-drag/Time.fixedDeltaTime) * initSpeed * 10;
Stupid, but nearly touching these two absolute values. I feel like I need to use log or something instead...Fri, 13 Jul 2018 23:31:45 GMTServailComment by Servail on Servail's comment
http://answers.unity.com/comments/1529060/view.html
There it is. I have 0.01666 fixedTimeStep = 60ftsps, so 30 drag is like middle ground for tests. By distance traveled (not behavior) 30 drag = 20 deceleration at initial speed 1, 40 at speed 2, 400 at speed 20 and so on. It's like in linear dependency of speed to stay fit. In this case object travels absolutely(!) the same distance. Here's all results with initial speed 1 (multiply as you want, like x2 speed - x2 deceleration):
drag - deceleration
59 - 58.985
55 - 54.55
50 - 48
45 - 40
40 - 30 (abs!)
35 - 25.7
30 - 20 (abs!)
25 - 16
20 - 12
15 - 8.6
10 - 5.46
5 - 2.61
1 - 0.508
I drew a graph... now I have one question: any relativity? Maybe my tests was wrong? I think I'm out...Fri, 13 Jul 2018 23:14:03 GMTServailComment by Servail on Servail's comment
http://answers.unity.com/comments/1528980/view.html
So you're saying there is no "classic" deceleration behavior (assuming manual simulation) equivalent of drag (because it's non-linear)? Or it can't be calculated from drag? I thought distance delta relativity to acceleration is also quadratic (or non-linear), so calculation is possible... I'm not using time at all, as you see; on the contrary, I want to avoid this because of raycasts. I'll do some tests soon, and as I wrote in OP-post, there is two obvious values of deceleration that fits drag (practically useless, but may be helpful in searching the right formula (if exists)).Fri, 13 Jul 2018 18:41:22 GMTServailComment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1528792/view.html
Drag is a non linear deceleration factor. So you can not give a single value as it will be changing every frame. However the current deceleration in this particular frame is of course
var decel = ownRigidbody.velocity * Mathf.Clamp01(dragToSimulate * Time.fixedDeltaTime);
This is the amount that is "subtracted" this frame from the velocity. However since this amount depends on the velocity itself it will be smaller the next frame.
<br>
In [reality drag / air resistance][1] actually has a quadratic relationship with the velocity, Unity use a simple linear relationship. This effectively is just a percentage per fixed update. So for example at a fixed rate of 50 (delta:0.02) and a drag factor of "5" you would get a 10% drop (since 0.02 * 5 == 0.1) every physics step. So if you have a RB at a speed of 100 after 1 frame without any other forces the velocity would drop to 90, then 81, 72.9, 65.61, 59.049, 53.1441, 47.8297, ...
So after about 7 frames the speed has been halfed. After another 7 frames it would be halfed again and would be around 25 and so on. In theory you would never reach 0. However due to floating point rounding after some steps the value may be rounded to 0. Though before that happens you won't notice any movement for quite a bit of time since the values can get extremels small.
<br>
Calculating the time it takes until the speed reaches 0 is impractical. However it's possible to calculate the time it takes until you reach a certain non zero velocity. However this assumes that no other forces are applied. If you have gravity this doesn't work [as the problem gets much more complicated][2]. For calculating the time without any other forces you can use the [same formular i've posted in this answer][3]
[1]: https://en.wikipedia.org/wiki/Drag_(physics)
[2]: http://answers.unity.com/answers/962581/view.html
[3]: http://answers.unity.com/answers/1514259/view.htmlFri, 13 Jul 2018 07:55:05 GMTBunny83Comment by Harinezumi on Harinezumi's comment
http://answers.unity.com/comments/1528785/view.html
Ah, you are right, now I understand. The velocity change would be `ownRigidbody.velocity * Mathf.Clamp01(dragToSimulate * Time.fixedDeltaTime)`, this is already in the same unit as the velocity (meters / second if you interpret a unit distance as 1m). And if my physics knowledge doesn't fail me (which is quite possible), the deceleration is actually `dragToSimulate`!Fri, 13 Jul 2018 07:41:33 GMTHarinezumiComment by Servail on Servail's comment
http://answers.unity.com/comments/1528579/view.html
This is how to simulate drag (description what drag does, not conversion) - that's what I'm already know. The thing I need is deceleration value (in meters per second squared) "extracted" from drag to use in formulas. Or maybe specific formulas for stopping distance and speed after traverse that are using drag directly (which I told in op-post, btw).Thu, 12 Jul 2018 16:53:33 GMTServailComment by Harinezumi
http://answers.unity.com/comments/1528452/view.html
Drag is unfortunately one of those variables that has very bad description, so it is unclear what it does exactly. But what you wrote, that it is modifying velocity in `FixedUpdate()` based on `fixedDeltaTime` seems to be correct.<br>
In which case, I would use the following conversion (**NOTE**: I have *NOT* tested this, just used the info you gave to shape it into a script):<br>
public class DragToDeceleration : MonoBehaviour {
private Rigidbody ownRigidbody;
private float dragToSimulate = 0;
private void Awake () {
ownRigidbody = GetComponent<Rigidbody>();
UpdateDragToSimulate();
}
private void UpdateDragToSimulate () {
if (ownRigidbody.drag != 0) {
dragToSimulate = ownRigidbody.drag;
ownRigidbody.drag = 0;
}
}
private void FixedUpdate () {
UpdateDragToSimulate();
ownRigidbody.velocity *= 1 - Mathf.Clamp01(dragToSimulate * Time.fixedDeltaTime);
}
}Thu, 12 Jul 2018 12:16:57 GMTHarinezumi