Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rigidbody linear damping has non-intuitive behavior around 1.0 #19182

Closed
Bauxitedev opened this issue May 26, 2018 · 7 comments · Fixed by #37314
Closed

Rigidbody linear damping has non-intuitive behavior around 1.0 #19182

Bauxitedev opened this issue May 26, 2018 · 7 comments · Fixed by #37314
Assignees
Milestone

Comments

@Bauxitedev
Copy link

Bauxitedev commented May 26, 2018

Godot version:
3.0.2 Mono

OS/device including version:
KDE Neon

Issue description:

When adjusting the linear damping of a rigid body in the range 0.98 to 1.02, the difference between 0.98 and 0.99 is marginal, but going from 0.99 to 1 suddenly causes a huge spike in the amount of dampening applied. Then going from 1 to 1.01 has a marginal effect again.

This is really annoying because for one of my projects, a damping on 0.99 was not enough, but a damping of 1.0 is way too much. There's no way to get a value inbetween. (0.999 is rounded to 1 in the editor)

This is using the DEFAULT physics engine, by the way.

Demonstration:
output

Might be related: #14650

Steps to reproduce:

  1. Create a Rigidbody, set linear damping to 0.99 and run the project. Observe behaviour.
  2. Set its linear damping to 1.0 and observe it suddenly falls much more slowly.

Minimal reproduction project:
dampingbug.zip

@mhilbrunner
Copy link
Member

cc @AndreaCatania

@AndreaCatania
Copy link
Contributor

The damping seems applied correctly. I don't know if this is a feature or a bug. I need to open an issue to the Bullet Physics github to assert it

@akien-mga akien-mga added this to the 3.2 milestone Jan 26, 2019
@jitspoe
Copy link
Contributor

jitspoe commented Jul 31, 2019

From looking at the code, it seems damping is designed to be in the [0-1) range. Here's what it does in bullet:

m_linearVelocity *= btPow(btScalar(1) - m_linearDamping, timeStep);

So if your damping is 1, it should actually have no movement, and > 1 should... I guess move it backward? I guess the bigger problem is that you can't enter values with more than 2 decimal places, since it seems like you might need to have a really-close-to-1 value. I guess you could add a script to your object and set the value from that so you have more digits available?

@akien-mga
Copy link
Member

Maybe damping should be exposed with a different scale? You need a ridiculous precision to be able to use a damping value as defined by the bullet equation:

(1-0,99)^0.016667
= 0,92611730648509949065

(1-0,999)^0.016667
= 0,89124888595498392525

(1-0,99999)^0.016667
= 0,82540101766847533075

(1-0,999999)^0.016667
= 0,79432457671599994306

(1-0,9999999)^0.016667
= 0,7644181672531883877

(1-0,999999999999)^0.016667
= 0,63095153317505247888

(1-0,9999999999999999)^0.016667
= 0,54116288077988569416

(1-0,9999999999999999999)^0.016667
= 0,48231081461526290744

(1-0,999999999999999999999999)^0.016667
= 0,39809983721594934885

@AndreaCatania
Copy link
Contributor

Hello @erwincoumans, in the PR #37314 we are considering to change the damping behaviour in order to be more controllable. See: #19182 (comment)

However, By reading this https://code.google.com/archive/p/bullet/issues/74 is possible to see that the formula was changed and it seems the cause of this weird behaviour.

Is this behaviour expected?

@erwincoumans
Copy link

erwincoumans commented Mar 28, 2020

Damping us expected to be in the range [0..1], best closer to 0 not 1. I would implement custom damping in a pretick callback. Or just implement your own version behind an #ifdef, happy to add merge it in the Bullet repo (but leave default as-is, I don't want to break the API).

@AndreaCatania
Copy link
Contributor

@erwincoumans Thanks for the replay, Do you think it's expected this behavioural differences between a body with damping 0.99 and 1.0?

We would expect something more smooth so would be useful understand if there is a problem or why it's expected to work as so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants