godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.85k stars 20.15k forks source link

Incorrect inertia with custom center of mass #74305

Open Lemonymous opened 1 year ago

Lemonymous commented 1 year ago

Godot version

v4.0.stable.mono.official [92bee43ad]

System information

Windows 10, Forward+, NVIDIA GeForce GTX 1050 Ti (31.0.15.1694)

Issue description

When a RigidBody2D has center_of_mass_mode = RigidBody2D.CENTER_OF_MASS_MODE_CUSTOM, and a custom center_of_mass as well as inertia set to 0; the rigid body's auto computed inertia can be incorrect.

A video of the attached mrp - Both boxes have the same size polygon, and inertia set to 0. So their inertia should be calculated to the same amount. However, the right box rotates slower.

https://user-images.githubusercontent.com/10490534/222751892-74e9f5da-ce99-4f81-8e8b-247e71447bcd.mp4

Steps to reproduce

Minimal reproduction project

This project shows two boxes with the same size polygon side by side. The left box's polygon is constructed around 0,0 The right box's polygon is constructed around 150,150

test center of mass.zip

Lemonymous commented 1 year ago

Does this have something to do with it? https://github.com/godotengine/godot/blob/61d2c855114c824f5ca27ded0a1fa71cc7b21134/servers/physics_2d/godot_body_2d.cpp#L70

Should it not check if the body has a custom center of mass?

Lemonymous commented 1 year ago

Possibly related to issue #55148

EGA-SUPREMO commented 1 month ago

This can be troublesome, my game features a destructible terrain, and when a new polygon is divided, the function Geometry2D.clip_polygons() returns a polygon with a high offset, this can be workaround with transform2d or something, but still isnt ideal