summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-09 18:16:45 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-08-09 20:21:04 -0700
commitec9fed69f4676e42e677c551423cd5f5c8f13100 (patch)
treea1835870914ec82443c149f9bad7a5ebebc80b34 /scene/2d
parentf3ddc14d3829ed09d6eab81811bcfb1314626ddf (diff)
Fix 3D moving platform logic
Same thing that was already done in 2D, applies moving platform motion by using a call to move_and_collide that excludes the platform itself, instead of making it part of the body motion. Helps with handling walls and slopes correctly when the character walks on the moving platform. Also made some minor adjustments to the 2D version and documentation. Co-authored-by: fabriceci <fabricecipolla@gmail.com>
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/physics_body_2d.cpp2
-rw-r--r--scene/2d/physics_body_2d.h3
2 files changed, 3 insertions, 2 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 00eeb60192..9235a2290e 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1075,7 +1075,7 @@ void CharacterBody2D::move_and_slide() {
floor_normal = Vector2();
floor_velocity = Vector2();
- if (current_floor_velocity != Vector2()) {
+ if (current_floor_velocity != Vector2() && on_floor_body.is_valid()) {
PhysicsServer2D::MotionResult floor_result;
Set<RID> exclude;
exclude.insert(on_floor_body);
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 7a319aabc9..c20372fe75 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -292,6 +292,8 @@ private:
Ref<KinematicCollision2D> _get_slide_collision(int p_bounce);
+ void _set_collision_direction(const PhysicsServer2D::MotionResult &p_result);
+
bool separate_raycast_shapes(PhysicsServer2D::MotionResult &r_result);
void set_safe_margin(real_t p_margin);
@@ -314,7 +316,6 @@ private:
const Vector2 &get_up_direction() const;
void set_up_direction(const Vector2 &p_up_direction);
- void _set_collision_direction(const PhysicsServer2D::MotionResult &p_result);
protected:
void _notification(int p_what);