Description
Tested versions
- Reproducible in: 4.3.stable
System information
Windows 10 - Vulkan (Forward+) - NVIDIA RTX 3060
Issue description
Jolt was just integrated to Godot, so I believe this should be in Godot issues. If not let me know!
When using Jolt Physics in Godot 4, and trying to get collision contact points between bodies, calling state.get_contact_collider_position(index) for a RigidBody3D results in an "Index out of bounds" error if the body gets in sleep mode. This occurs even when get_contact_count() reports a value greater than 0. The error does not occur with default Godot Physics
The error:
_physics_process(): Index p_contact_idx = 0 is out of bounds (body->get_contact_count() = 0).
<C++ Source> src\objects\jolt_physics_direct_body_state_3d.cpp:217 @ _get_contact_collider_position()
This behavior affects contact point calculations for bodies that are stationary but still colliding with other objects
Steps to reproduce
- Set up a scene with two colliding RigidBody3D objects.
- Ensure Jolt Physics is installed and defined as current physics engine
- Enable contact_monitor and set max_contacts_reported to a non-zero value (e.g., 5).
- Let one of the bodies come to rest, causing it to enter sleep mode.
- Execute the code below inside the body that has come to a rest:
extends RigidBody3D
func _ready() -> void:
contact_monitor = true
max_contacts_reported = 5
func _physics_process(_delta: float) -> void:
# Get body rid
var rid := get_rid()
# Get body physics state
var state := PhysicsServer3D.body_get_direct_state(rid)
for i in get_contact_count():
print("Contact count: ", get_contact_count(),
" ", state.get_contact_collider_position(i))
Expected Behavior:
state.get_contact_collider_position(index) should return valid contact points if get_contact_count() > 0, even when the body is in sleep mode.
Observed Behavior:
An "Index out of bounds" error occurs, and get_contact_collider_position() fails.
Minimal reproduction project (MRP)
I had to remove macOS, Linux and android libraries from the Jolt folder to make the file small enough to upload. You can always reinstall jolt add-on to make sure.