Skip to content

Commit 771a497

Browse files
doc: Add physics query workaround (#546)
This adds a workaround for using physics queries during the rollback loop, without having to resort to full physics state rollbacks. --------- Co-authored-by: Tamás Gálffy <ezittgtx@gmail.com>
1 parent 88721ca commit 771a497

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/netfox/tutorials/rollback-caveats.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ i.e.
7272
* ChacacterBody (2D and 3D) - [move_and_collide()] ( which has a test only
7373
mode )
7474

75+
While kinematic nodes like `CharacterBody3D` can be used with rollback, physics
76+
queries can still cause issues (e.g.
77+
`PhysicsDirectSpaceState3D.intersect_shape()`). This is due to the lack of
78+
updates mentioned earlier. To work around this, run the following for each
79+
`CollisionObject` that has its position rolled back before each tick of the
80+
rollback loop:
81+
82+
```gdscript
83+
# Works for both Jolt and GodotPhysics3D.
84+
func _force_update_physics_transform():
85+
PhysicsServer3D.body_set_mode(get_rid(), PhysicsServer3D.BODY_MODE_STATIC)
86+
PhysicsServer3D.body_set_state(get_rid(), PhysicsServer3D.BODY_STATE_TRANSFORM, global_transform)
87+
PhysicsServer3D.body_set_mode(get_rid(), PhysicsServer3D.BODY_MODE_KINEMATIC)
88+
```
89+
90+
The above forces an update by setting the object to static, updating its
91+
transform, and then setting it back to its original, kinematic state.
92+
93+
Note that the above code needs to run for any kinematic object that is to be
94+
detected by the query and is manipulated during rollback.
95+
7596
!!!tip
7697
The *netfox.extras* addon provides optional support for physics simulation
7798
with rollback. See [Physics](../../netfox.extras/guides/physics.md)

0 commit comments

Comments
 (0)