From 56d4b9b1aecab40dd9332b1443b1449b2408a429 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 17 Jan 2019 12:01:09 -0300 Subject: [PATCH] Fix functions to get direct contacts from shapes, closes #19618 --- scene/resources/shape_2d.cpp | 14 +++++++------- scene/resources/shape_2d.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 0254945c006..4a41db38c6e 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -59,27 +59,27 @@ bool Shape2D::collide(const Transform2D &p_local_xform, const Ref &p_sh return Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), NULL, 0, r); } -Variant Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { +Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { - ERR_FAIL_COND_V(p_shape.is_null(), Variant()); + ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; int contacts = 0; if (!Physics2DServer::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) - return Variant(); + return Array(); Array results; results.resize(contacts * 2); - for (int i = 0; i < contacts; i++) { + for (int i = 0; i < contacts * 2; i++) { results[i] = result[i]; } return results; } -Variant Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform) { +Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform) { - ERR_FAIL_COND_V(p_shape.is_null(), Variant()); + ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; int contacts = 0; @@ -89,7 +89,7 @@ Variant Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, cons Array results; results.resize(contacts * 2); - for (int i = 0; i < contacts; i++) { + for (int i = 0; i < contacts * 2; i++) { results[i] = result[i]; } diff --git a/scene/resources/shape_2d.h b/scene/resources/shape_2d.h index cf6b38dddae..da9b80477cd 100644 --- a/scene/resources/shape_2d.h +++ b/scene/resources/shape_2d.h @@ -53,8 +53,8 @@ public: bool collide_with_motion(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion); bool collide(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform); - Variant collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion); - Variant collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform); + Array collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion); + Array collide_and_get_contacts(const Transform2D &p_local_xform, const Ref &p_shape, const Transform2D &p_shape_xform); virtual void draw(const RID &p_to_rid, const Color &p_color) {} virtual Rect2 get_rect() const { return Rect2(); }