diff options
Diffstat (limited to 'scene/resources/capsule_shape_2d.cpp')
-rw-r--r-- | scene/resources/capsule_shape_2d.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index e5edba8a67..596fa70f15 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -38,11 +38,11 @@ Vector<Vector2> CapsuleShape2D::_get_points() const { Vector<Vector2> points; const real_t turn_step = Math_TAU / 24.0; for (int i = 0; i < 24; i++) { - Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); + Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -height * 0.5 + radius : height * 0.5 - radius); - points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * get_radius() + ofs); + points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * radius + ofs); if (i == 6 || i == 18) { - points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * get_radius() - ofs); + points.push_back(Vector2(Math::sin(i * turn_step), Math::cos(i * turn_step)) * radius - ofs); } } @@ -59,7 +59,7 @@ void CapsuleShape2D::_update_shape() { } void CapsuleShape2D::set_radius(real_t p_radius) { - radius = p_radius; + radius = MIN(p_radius, height * 0.5); _update_shape(); } @@ -68,11 +68,7 @@ real_t CapsuleShape2D::get_radius() const { } void CapsuleShape2D::set_height(real_t p_height) { - height = p_height; - if (height < 0) { - height = 0; - } - + height = MAX(p_height, radius * 2); _update_shape(); } @@ -93,15 +89,11 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { } Rect2 CapsuleShape2D::get_rect() const { - Vector2 he = Point2(get_radius(), get_radius() + get_height() * 0.5); - Rect2 rect; - rect.position = -he; - rect.size = he * 2.0; - return rect; + return Rect2(0, 0, radius, height); } real_t CapsuleShape2D::get_enclosing_radius() const { - return radius + height * 0.5; + return height * 0.5; } void CapsuleShape2D::_bind_methods() { |