-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Inertia not updated when calling Body.setMass() #378
Comments
Not recalculating inertia is probably good optimization if plenty of bodies change their mass a little. But atleast a mention in the comment or taking third parameter |
Good spot. Recalculating inertia in this case is easy, we can just do: var moment = body.inertia / (body.mass / 6);
body.inertia = moment * (mass / 6); I'll tag this as a bug, thanks. |
This code might break if inertia is set in setMass function. Might have to separately call I really like how you have structured the library. Well done! |
Ran into this bug too, had me real confused for a hot minute. I'm still a bit confused as to why the inertia not being updated only seemed to be effecting the linear velocity and not the rotational velocity. on an unrelated note:
I assume is supposed to be: |
I started using Matter.js in my game editor where you can create bodies and edit them later on. I noticed that these two code snippets give different results:
Both of the snippets will set density to 0.01, but since inertial is only calculated on creation of the body, these snippets will result in different body.inertial value. Therefore bodies act really weird.
When density changes, mass is recalculated. Shouldn't inertial be also recalculated when mass changes? If you think so, I would be happy to contribute.
The text was updated successfully, but these errors were encountered: