godot-jolt / godot-jolt

Godot Jolt is a Godot extension that integrates the Jolt physics engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collisions between static and locked bodies causes NaNs

Jo-Jox opened this issue · comments

Hi, I encountered a very weird bug on Godot 4.2 .NET version with Jolt physics. I have a rotating rectangle with all linear axes locked and both angular x and angular y locked. I added a constant torque value of 100 in the inspector and ran the project. In godot without jolt, it spins and can be interacted with. With jolt, it does not spin and touching it will teleport you somewhere and cause 30 of those errors :

E 0:00:10:0770 instance_set_transform: Condition "!v.is_finite()" is true.
<C++ Source> servers/rendering/renderer_scene_cull.cpp:922 @ instance_set_transform()

Is there anything I did wrong ? Thanks a lot.

Hello,

@Jo-Jox: Are you able to provide a minimal repro? I wasn't able to reproduce this with my own sample: example.zip (note I didn't include the 'addons' folder in the zip, you need to copy it from elsewhere). Also, is your constant torque on the Z axis? (X or Y should not result in any rotation since the axis are locked)

Note to @mihe: I'm not clearing any locked components in Body::AddForce/AddTorque (or any of the set velocity functions) because the assumption is that the user will not try to force a velocity on a locked axis. So, while the inertia tensor should be zero in the locked axis direction, there could be some residual value that ends up in a locked axis direction. To prevent this, these lines should be changed to clear components for locked axis:

p_jolt_body.AddForce(to_jolt(constant_force));
p_jolt_body.AddTorque(to_jolt(constant_torque));

For translation there is MotionProperties::LockTranslation. I will make a function for rotation too.

Hello @jrouwe and thanks for looking at my issue.

I have removed everything else from my scene to only left the weird behaving objects so you can see what I mean. The weird thing is when creating a whole new project the issue doesn't seem to bee there anymore... There will be some errors as a deleted a whole bunch of things but the issue is still testable. I removed the jolt folders due to size so it must be installed again.
Example.zip

I've further minimized the example: Example2.zip

The reason why it is not rotating is that there is a collision between the floor and the rotating body. If you disable the collision between floor and rotating body or if you shift the floor a fraction downwards things start to work. I don't know yet how this ends up producing NaNs but since the floor and rotating body are exactly touching, my guess is that there is some sort of floating point problem.

Thanks a lot, you are right. Moving up the Rigidbody by .001m corrects the issue.

I found the issue and created a fix. Note that @mihe still needs to integrate this fix into godot-jolt before you can use it.

Thank you for chasing this one down, @jrouwe.

I'm not clearing any locked components in Body::AddForce/AddTorque (or any of the set velocity functions) because the assumption is that the user will not try to force a velocity on a locked axis. So, while the inertia tensor should be zero in the locked axis direction, there could be some residual value that ends up in a locked axis direction.

I'll make sure to fix that. There are a couple of other places that will presumably need the same change.

The fix for this is included in the newly released 0.12.0-stable.