Rotating rigid body does not update other rigid bodies

How do I make rotations of a rigid body affect others touching it? I have a floating rigid body in my world (mass 0) and I have custom keybinds to change the rotation, along each axis. But when I place a different rigid body (with mass of greater than 0) on top of the floating rigid body then rotate it, the floating box visually rotates and goes through the new box. The new box seems to follow collision box of the floating boxes original rotation.

sample code for rotating the floating box leftward along the x axis:

rotatable.rotate(-1*FastMath.DEG_TO_RAD, 0f, 0f);
					
RigidBodyControl physics = new RigidBodyControl(0.0f);
physics.setPhysicsRotation(rotatable.getLocalRotation());

rotatable.addControl(physics);
bulletAppState.getPhysicsSpace().add(physics);
physics.setPhysicsRotation(rotatable.getLocalRotation());

For the other axes it is the same, just with the numbers adjusted to make the box rotate in the appropriate direction.

Update: after further testing it kinda works as in the new boxes follow the new collision box if they have been created after rotation, but sometimes it is still a little bit off??
Also, the floating box still visually goes through the new objects.

maybe you could post a little video, gravy?

I’m not sure what you are getting and what you are wanting to get

I advise using debug visualization to look at what’s going on in physics space:

bulletAppState.setDebugEnabled(true);

That should clarify what’s going on.

One possibility is that you are rotating the geometry but not the physics object.

If you post a short, self-contained, correct example, we should be able to diagnose the issue. Otherwise we must play the “20 questions” game:

Are you using Minie or jme3-jbullet? Which version?
Are you using RigidBodyControl? If so, what modes are the controls in: dynamic or kinematic?
Are the boxes added to both the physics space and the scene graph?
…

Based on the limited information, I’m with sgold with my guesses: either you are rotating the spatial and not the body or the 0 mass body is not kinematic.

…given your description, the latter seems most likely.

1 Like

pspeed thank you! My issue was that it was not kinematic.

1 Like

So uh this might be irrelevant but I managed to not only make it so the game doesn’t run horribly after a few seconds worth of rotating the floating cube but also reduce the lines of code to make the physics rotate to just 1 line! After this I feel so embarrassed…

Before:

RigidBodyControl physics = new RigidBodyControl(0.0f);
					
rotatable.addControl(physics);
bulletAppState.getPhysicsSpace().remove(rotatable.getControl(0));
bulletAppState.getPhysicsSpace().add(physics);
physics.setKinematic(true);
physics.setPhysicsRotation(rotatable.getLocalRotation());

Issue with this, is that it keeps on adding new instances of the control which pile up and eventually make it so hundreds of controls are attaching to the same box.

After:

((RigidBodyControl) rotatable.getControl(0)).setPhysicsRotation(rotatable.getLocalRotation());

Please let me know if this is a wrong, inefficient or sketchy way to achieve my goal, I am only new to jMonkeyEngine so I am not surprised if this too is wrong.

1 Like

A single-line solution isn’t necessarily better than a multi-line solution, but in this case, it is. However, it’s not the best possible solution.

If you put the RigidBodyControl into kinematic mode, then the physics library should automatically rotate and translate the physics object to match the rotatable:

rigidBodyControl.setKinematic(true);

There’s a whole page about RigidBodyControl in the Minie tutorials, including simple examples:

Wow, thank you I didn’t know that

1 Like