godot: RigidBody freezes in rotating Spatial
Godot version:
v3.2.4.beta.custom_build.e25984a74 Commit: d59414051b
OS/device including version:
OS: Arch Linux Backend: GLES3
Issue description:
What happens:
When putting a RigidBody with mode Rigid into a Spatial node which is rotating, the RigidBody physics seems to freeze/break.
What was expected: I expected that all physics happens to the local parent Spatial orientation. Especially when combined with a gravitational field, which is demonstrated in the video.
Steps to reproduce: The video shows how I (try to) bounce with the player against the box during different stages.
The sphere represents a planet, which is a RigidBody in static mode.
The box is a RigidBody in rigid mode, which is affected by a gravitational field.
Both are children of the RotationSpatial which exports the variable Rotation Enabled which starts or stops the rotation.
In short:
- Rotation on -> box freezes
- Rotation off -> box works again
Minimal reproduction project:
Project captures mouse pointer, which can be freed by pressing ESC. Clicking into the window, captures it again.
Project: rotation.zip
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 16 (9 by maintainers)
I tested it with Godot 4 and I have some interesting news. In the beginning it’s a bit laggy because my laptop is complete garbage and it seems to have problems with Vulkan in general.
https://user-images.githubusercontent.com/18660100/105396264-f8a16380-5c1f-11eb-9c8a-d59cd7c8c636.mp4
Nonetheless it seems to work as expected in the first place. (The outer smaller sphere is just to visualize the rotation, because Godot crashes on my machine when I try to apply a shader)
The Capsule is a static rigid body and is not a child of the rotating Node3D.
Godot: 4.0.dev Commit: a9b151c664d00d353640e6b2c52d026347230269 Project: godot_4_test_proj.zip
Quick hack to show the kind of procedure I had in mind.
Script attached to RigidBody:
This already results in (rotation speed increased):
https://user-images.githubusercontent.com/18660100/104953543-e2e53180-59c6-11eb-943a-766cad262c0e.mp4
Obviously buggy, but one can see where this is going. I would expect this to work way better, if this kind of “algorithm” is used in the core engine.
But ok, I will figure it out eventually.
I think this should go into docs repo with example. Even though circular motion is only a few lines of code, lots of people seem to not be able to grasp physics involved. You can approach it with proper simulation (gravity, centrifugal force, etc.) or just converting velocity into force and torque.
First you need to handle distance to rotation center, i.e. apply radial force in direction out or into your circle. Second, your remaining vector is perpendicular to radial vector. Just add it to the above. For torque you check angle between previous force vector and current one and apply torque if it is more than some small number to correct rotation.
On Mon, Jan 18, 2021 at 11:21 PM Camille Mohr-Daurat < notifications@github.com> wrote:
Ok, makes sense. Let’s make sure the documentation states very clearly how rigid body transformation works.
I could do that, but it would somewhat question the whole use of the scene tree concept, if child nodes can unexpectedly behave different, when they are children of a spatial.
I do not expect the children do be affected by the parents movement on a physics based level. E.g. forget the rotation for a moment. Imagine the following scene:
When I now would shake the
ShakingSpatial, I would not expect theRigidBodyto build up momentum relative to theWorldNodeand fly around. I would expect theRigidBodyto simply follow the translation of theShakingSpatialand behave physically correct within and relative to the theShakingSpatial. TheShakingSpatialwould be, in some way, its own inertial frame of reference for all its children.Back to the rotation example of this issue: I would not expect the box to build up centrifugal force. The box should simply follow the translation like any other static object plus the translation caused by collisions from within the
RotatingSpatial.For further clarification of my problem: Thanks for your advice so far, but I am less in search of an alternative solution. “Calculate it yourself” is almost every time a solution. At this point my question is more like if this is officially expected behavior or not?