summaryrefslogtreecommitdiff
path: root/scene/3d/physics_body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/physics_body.cpp')
-rw-r--r--scene/3d/physics_body.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 4c661e6a88..4e06b272e2 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -938,7 +938,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, Collision &r_colli
Transform gt = get_global_transform();
PhysicsServer::MotionResult result;
- bool colliding = PhysicsServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, margin, &result);
+ bool colliding = PhysicsServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, &result);
if (colliding) {
r_collision.collider_metadata = result.collider_metadata;
@@ -988,12 +988,15 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
on_floor = true;
floor_velocity = collision.collider_vel;
- /*if (collision.travel.length() < 0.01 && ABS((lv.x - floor_velocity.x)) < p_slope_stop_min_velocity) {
+ Vector3 rel_v = lv - floor_velocity;
+ Vector3 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v);
+
+ if (collision.travel.length() < 0.05 && hv.length() < p_slope_stop_min_velocity) {
Transform gt = get_global_transform();
- gt.elements[2] -= collision.travel;
+ gt.origin -= collision.travel;
set_global_transform(gt);
- return Vector3();
- }*/
+ return floor_velocity - p_floor_direction * p_floor_direction.dot(floor_velocity);
+ }
} else if (collision.normal.dot(-p_floor_direction) >= Math::cos(p_floor_max_angle)) { //ceiling
on_ceiling = true;
} else {
@@ -1041,12 +1044,13 @@ bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion)
ERR_FAIL_COND_V(!is_inside_tree(), false);
- return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, margin);
+ return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion);
}
void KinematicBody::set_safe_margin(float p_margin) {
margin = p_margin;
+ PhysicsServer::get_singleton()->body_set_kinematic_safe_margin(get_rid(), margin);
}
float KinematicBody::get_safe_margin() const {