JirkaDellOro / FUDGE

Furtwangen University Didactic Game Editor
https://jirkadelloro.github.io/FUDGE
MIT License
33 stars 27 forks source link

Torque respect Mass #349

Open JirkaDellOro opened 1 year ago

JirkaDellOro commented 1 year ago

I noticed, that applyTorque seems not to consider the mass of the rigidbody. Different masses of the same shape should result in different acceleration. See the test attached. Torque.zip

Dev-MarkoF commented 1 year ago

Thanks for the report i will look into it.

Update: It is definetly not a Fudge implementation problem, currently i believe that torque is actually applied without the actual mass in mind within the oimo step, only direct forces are. Which seems to result in a constant acceleration increment regardless of the mass. It looks like only the angular damping is used, since the acceleration has a limit where the damping is >= to the added acceleration each frame. But i first have to find the actual step in other calculations to retrace how mass is applied there and look into if it is a bug or intended by the original author.

In the meantime mass could be faked by scaling the angularDamping to a factor that suits for the increase of mass, compared to other RBs.

Dev-MarkoF commented 1 year ago

Some experiments in Unity result in the behaviour i exptected. AddTorque not considering mass is a intentional decision, but also a bug. Depending on the opinion about game physics. Since in general there is no possibility in reality to add torque with a force on the center of mass, the AddTorque is not really working with "force" but more in the way of a "rotationAcceleration" for users to easily apply rotational velocity without thinking about where to apply force. So since it's not a physical process, but a purely fictional you can think of 2 behaviours.

User 1 wants to spin with an acceleration of 1m/s per Update User 1 wants to increase the theoretical spin by 1 m/s per Update on a 1kg body, but would not achieve their goal on a 2kg body.

Unity does expose a option to AddTorque that is considering this, it's called "forceMode", since Unity has the opinion of an easy learning curve, even if the user does not learn the actual behaviour, the forceMode is by default "addTorque as Force". But you can change it to behave like OIMO with ForceMode.acceleration

Which then applies the "torque" as scaled by mass, which in general is also an acceleration at the center of mass, which is a = F/m

So the solution would be to add a similar option to the way unity is doing, and expose a kind of forceMode, and apply the torque as "force" then. But unlike Unity i would actually set the default behaviour to be the way it is now, to accelerate by the value given, instead of considering mass, to keep it in line with how OIMO is opinionated so far. And then also add a general setting to change the default for the whole physics.world, so you do not have to switch it on for each body.

Dev-MarkoF commented 1 year ago

Change is implemented, i will update / create pull request, when i have looked into the other problems. (or until next semester) Now torque change can be treated as either a force on the "torque" or an actual acceleration (default). Default can be set in the physics.settings.