Godot Version
v4.4.stable.official [4c311cbee]
Question
I’m writing a character controller for my player character in a 3D game. I have several animations for my character, and for a few of them - such as climbing over walls - I need to set the character position explicitly. So instead of using Godot’s usual move_and_slide()
command to move the character, when these animations are playing I’m keeping track of the root bone and setting the global_transform
in the _physics_process
step by directly assigning to it.
This works fairly well, except for when the animation finishes and I want to switch back to my idle pose. Even though my model should be on the ground, the is_on_floor()
method return false. If I try to shove my player into the floor by setting the velocity and then calling move_and_slide()
the model moves as if there are no other physics objects present. The physics simulation doesn’t seem to recognize my change until the next frame. This is causing my player to needlessly enter the falling state for one frame before physics kicks in and I can tell I’m on the floor again.
I’ve tried setting the physics transform using PhysicsServer3D.body_set_state()
and also waiting a frame with await get_tree().physics_frame
, but neither work. Is there anything I can do to update physics after setting my character’s transform explicitly?