Fix move_and_collide causing sliding on slopes

Make sure the direction of the motion is preserved, unless the depth is
higher than the margin, which means the body needs depenetration in any
direction.

Also changed move_and_slide to avoid sliding on the first motion, in
order to avoid issues with unstable position on ground when jumping.

Co-authored-by: fabriceci <fabricecipolla@gmail.com>
This commit is contained in:
PouleyKetchoupp 2021-06-24 19:25:26 -07:00
parent 92f20fd70e
commit 9758a75221
10 changed files with 138 additions and 25 deletions

View file

@ -493,6 +493,9 @@ public:
Vector2 collision_point;
Vector2 collision_normal;
Vector2 collider_velocity;
real_t collision_depth = 0.0;
real_t collision_safe_fraction = 0.0;
real_t collision_unsafe_fraction = 0.0;
int collision_local_shape = 0;
ObjectID collider_id;
RID collider;
@ -619,6 +622,9 @@ public:
RID get_collider_rid() const;
Object *get_collider() const;
int get_collider_shape() const;
real_t get_collision_depth() const;
real_t get_collision_safe_fraction() const;
real_t get_collision_unsafe_fraction() const;
};
typedef PhysicsServer2D *(*CreatePhysicsServer2DCallback)();