From ac1885925c8d391794475a0099a796bb9724b548 Mon Sep 17 00:00:00 2001 From: FranckRJ Date: Sun, 14 May 2023 15:46:57 +0200 Subject: [PATCH] Fixed width of CapsuleShape2D::get_rect + set center to center of shape The width of the rect was only half of the width of the shape, and the 0;0 coord was at the top left of the rect. Now the width properly matches the width of the shape, and the 0;0 coord is at the center of the shape. It should match the behavior of Godot 3.X. (cherry picked from commit ab5462e386b2b353adb6533bdb7a17d020598be8) --- scene/resources/capsule_shape_2d.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 5309e54846a..8268040ed9d 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -97,7 +97,8 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { } Rect2 CapsuleShape2D::get_rect() const { - return Rect2(0, 0, radius, height); + const Vector2 half_size = Vector2(radius, height * 0.5); + return Rect2(-half_size, half_size * 2.0); } real_t CapsuleShape2D::get_enclosing_radius() const {