1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-06 17:25:19 +00:00

Fix test_move reporting collision when touching another body

Reporting rest collision information is needed for move_and_collide and
move_and_slide so floor detection can be done properly, but in the case
of just testing the motion for collision, it makes sense to return false
if the body is able to move all along the path without being stopped.

Updated the logic in test_move and clarified the documentation for
test_move and move_and_collide.

(cherry picked from commit 1560c8b5aa)
This commit is contained in:
PouleyKetchoupp
2021-11-09 17:03:25 -07:00
committed by Rémi Verschelde
parent 7344beafdd
commit f9710ecb5e
4 changed files with 36 additions and 7 deletions

View File

@@ -1259,7 +1259,15 @@ Vector3 KinematicBody::get_floor_velocity() const {
bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia) {
ERR_FAIL_COND_V(!is_inside_tree(), false);
return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia);
PhysicsServer::MotionResult result;
bool colliding = PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia, &result);
if (colliding) {
// Don't report collision when the whole motion is done.
return (result.collision_safe_fraction < 1.0);
} else {
return false;
}
}
bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) {