diff options
Diffstat (limited to 'scene/2d/physics_body_2d.cpp')
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 75fa6054ad..16df36aa24 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1228,15 +1228,16 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) { -Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const Vector2& p_floor_direction,int p_max_bounces) { +Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const Vector2& p_floor_direction,float p_slope_stop_min_velocity,int p_max_bounces) { - Vector2 motion = p_linear_velocity*get_fixed_process_delta_time(); + Vector2 motion = (move_and_slide_floor_velocity+p_linear_velocity)*get_fixed_process_delta_time(); Vector2 lv = p_linear_velocity; move_and_slide_on_floor=false; move_and_slide_on_ceiling=false; move_and_slide_on_wall=false; move_and_slide_colliders.clear(); + move_and_slide_floor_velocity=Vector2(); while(motion!=Vector2() && p_max_bounces) { @@ -1244,13 +1245,21 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V if (is_colliding()) { + if (p_floor_direction==Vector2()) { //all is a wall move_and_slide_on_wall=true; } else { if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad(45))) { //floor + + move_and_slide_on_floor=true; move_and_slide_floor_velocity=get_collider_velocity(); + + if (get_travel().length()<1 && ABS((lv.x-move_and_slide_floor_velocity.x))<p_slope_stop_min_velocity) { + revert_motion(); + return Vector2(); + } } else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad(45))) { //ceiling move_and_slide_on_ceiling=true; } else { @@ -1367,7 +1376,7 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody2D::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody2D::move_to); - ObjectTypeDB::bind_method(_MD("move_and_slide","linear_velocity","floor_normal","max_bounces"),&KinematicBody2D::move_and_slide,DEFVAL(Vector2(0,0)),DEFVAL(4)); + ObjectTypeDB::bind_method(_MD("move_and_slide","linear_velocity","floor_normal","slope_stop_min_velocity","max_bounces"),&KinematicBody2D::move_and_slide,DEFVAL(Vector2(0,0)),DEFVAL(5),DEFVAL(4)); ObjectTypeDB::bind_method(_MD("test_move","rel_vec"),&KinematicBody2D::test_move); ObjectTypeDB::bind_method(_MD("get_travel"),&KinematicBody2D::get_travel); |