diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/resources/capsule_shape_2d.cpp | 21 | ||||
-rw-r--r-- | scene/resources/capsule_shape_2d.h | 2 |
2 files changed, 11 insertions, 12 deletions
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index e5edba8a67..8f7f3edc28 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); } } @@ -60,6 +60,9 @@ void CapsuleShape2D::_update_shape() { void CapsuleShape2D::set_radius(real_t p_radius) { radius = p_radius; + if (radius > height * 0.5) { + height = radius * 2; + } _update_shape(); } @@ -69,8 +72,8 @@ real_t CapsuleShape2D::get_radius() const { void CapsuleShape2D::set_height(real_t p_height) { height = p_height; - if (height < 0) { - height = 0; + if (radius > height * 0.5) { + height = radius * 2; } _update_shape(); @@ -93,15 +96,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() { diff --git a/scene/resources/capsule_shape_2d.h b/scene/resources/capsule_shape_2d.h index 439b67e8c3..37b6c52c0e 100644 --- a/scene/resources/capsule_shape_2d.h +++ b/scene/resources/capsule_shape_2d.h @@ -36,7 +36,7 @@ class CapsuleShape2D : public Shape2D { GDCLASS(CapsuleShape2D, Shape2D); - real_t height = 20.0; + real_t height = 30.0; real_t radius = 10.0; void _update_shape(); |