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

apply_torque_impulse() problem with Bullet #21487

Closed
HugoSlt opened this issue Aug 27, 2018 · 8 comments
Closed

apply_torque_impulse() problem with Bullet #21487

HugoSlt opened this issue Aug 27, 2018 · 8 comments

Comments

@HugoSlt
Copy link

HugoSlt commented Aug 27, 2018

Godot version:
Godot 3.1 #2928091

OS:
Ubuntu 18.04

Issue description:
With a simple pendulum (a RigidBody attached with a HingeJoint), if we apply
a single torque impulse, we expect the pendulum to start oscillating.
It correctly does so with GodotPhysics but it doesn't with Bullet. With
Bullet the pendulum starts rotating at constant speed.

Here is a video of the problem, first Bullet, then GodotPhysics.
apply_torque_prob

Steps to reproduce:
Create a RigidBody attached to a HingeJoint, apply a single torque impulse on it with apply_torque_impulse(). Switch between Bullet and GodotPhysics in the project settings
to observe the different behaviors.

Minimal reproduction project:
apply_torque.zip

@akien-mga
Copy link
Member

CC @AndreaCatania

@TGRCdev
Copy link
Contributor

TGRCdev commented Aug 27, 2018

Currently testing on a build of master branch, commit 2db4942 on Ubuntu 18.04

The reproduction project gives the same result as the above gif. However, when I tried to recreate the project, I didn't encounter the bug:
bullet_joint

Here's my project recreation: BulletJoints.zip

@HugoSlt
Copy link
Author

HugoSlt commented Aug 27, 2018

I confirm TGRCdev observation, same here : apply_torque.zip has the problem and BulletJoints.zip doesn't.

I think I found where the issue comes from : the centers of our RigidBodies are not at the same place.

In BulletJoints.zip, if you move the children of the Box RigidBody (i.e MeshInstance & CollisionShape) so that when you select the Box, the center of the Box is aligned with the pivot point like this :
center
then you get the same problem as in apply_torque.zip.

@TGRCdev
Copy link
Contributor

TGRCdev commented Aug 27, 2018

Dang, nice find. Looks like Bullet uses the RigidBody node's position, while GodotPhysics uses the CollisionShape node's position.

@HugoSlt
Copy link
Author

HugoSlt commented Aug 28, 2018

So actually it's more a problem of convention than an implementation issue. Maybe those details should be clearly documented somewhere in the docs, especially those points :

@TGRCdev
Copy link
Contributor

TGRCdev commented Aug 28, 2018

So I've looked a bit further into the differences in Bullet and Godot's center_of_masses, and I have a modified apply_impulse.zip to show some of my findings.

apply_torque_modified.zip

Green Ball = RigidBody's origin
Red Ball = Center of mass
Blue Square = StaticBody

Left Slider = CollisionShape y translation
Top Slider = StaticBody y translation
Right Slider = RigidBody y translation

value of center_of_mass pulled from PhysicsDirectBodyState


GodotPhysics

gdphysics_test

  • GDPhysics' center of mass is described in positional offset from the RigidBody node. (Took me a while to figure this out.)
  • The center of mass is located at the center of all CollisionShapes under the RigidBody node.
  • Multiple CollisionObjects modify the center of mass
  • Changes to RigidBody.translation are completely ignored

Bullet

bullet_test
(The red ball is hidden under the green ball, because the center of mass is the RigidBody node's origin)

  • Bullet's center of mass is described in global coordinates
  • The center of mass is located at the RigidBody's origin
  • Multiple CollisionObjects do not modify the center of mass, it always stays at RigidBody node's origin
  • Changes to RigidBody.translation briefly moves the RigidBody node away from the HingeJoint, but it snaps back after a few frames.

Overall, I think we should follow Bullet's center of mass policy. Calculated center of mass might not always be accurate (i.e. an axe with a metal head and a wooden handle), and moving CollisionShapes and MeshInstances is much simpler.

@AndreaCatania
Copy link
Contributor

Yes I can confirm that in Bullet is possible to "Customize", by moving shapes, the center of mass. Would be awesome if someone could write it in the documentation.

@HugoSlt
Copy link
Author

HugoSlt commented Aug 28, 2018

Yes it's nice to be able to set the center of mass where we want by adjusting the relative position of the RigidBody/CollisionShapes.
Should we open a new issue on godot-docs to remember documenting this and close this issue ?

Edit : I've opened this issue as a remainder to talk about it in the docs

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

No branches or pull requests

4 participants