1
0
Fork 0

Merge pull request #99397 from yosoyfreeman/master

Allow `apply_floor_snap` to preserve the horizontal position regardless of `stop_on_slopes`
This commit is contained in:
Thaddeus Crews 2024-12-10 14:15:59 -06:00
commit b88fd31687
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
2 changed files with 16 additions and 16 deletions

View File

@ -352,14 +352,14 @@ void CharacterBody2D::_apply_floor_snap(bool p_wall_as_floor) {
floor_normal = result.collision_normal;
_set_platform_data(result);
if (floor_stop_on_slope) {
// move and collide may stray the object a bit because of pre un-stucking,
// so only ensure that motion happens on floor direction in this case.
if (result.travel.length() > margin) {
result.travel = up_direction * up_direction.dot(result.travel);
} else {
result.travel = Vector2();
}
// Ensure that we only move the body along the up axis, because
// move_and_collide may stray the object a bit when getting it unstuck.
// Canceling this motion should not affect move_and_slide, as previous
// calls to move_and_collide already took care of freeing the body.
if (result.travel.length() > margin) {
result.travel = up_direction * up_direction.dot(result.travel);
} else {
result.travel = Vector2();
}
parameters.from.columns[2] += result.travel;

View File

@ -469,14 +469,14 @@ void CharacterBody3D::apply_floor_snap() {
_set_collision_direction(result, result_state, CollisionState(true, false, false));
if (result_state.floor) {
if (floor_stop_on_slope) {
// move and collide may stray the object a bit because of pre un-stucking,
// so only ensure that motion happens on floor direction in this case.
if (result.travel.length() > margin) {
result.travel = up_direction * up_direction.dot(result.travel);
} else {
result.travel = Vector3();
}
// Ensure that we only move the body along the up axis, because
// move_and_collide may stray the object a bit when getting it unstuck.
// Canceling this motion should not affect move_and_slide, as previous
// calls to move_and_collide already took care of freeing the body.
if (result.travel.length() > margin) {
result.travel = up_direction * up_direction.dot(result.travel);
} else {
result.travel = Vector3();
}
parameters.from.origin += result.travel;