diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-15 11:21:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-15 11:21:19 +0200 |
commit | 7d4c3035ad7a128198a791be1b3587b5a1b6a28f (patch) | |
tree | ba4207e700fa423742fac5588810270037677bf5 /scene | |
parent | 9a559ed5aa49a2ca5de1a688996d7e7364406a02 (diff) | |
parent | 350227013d2bccaab01c40d6bbf53c0834292168 (diff) |
Merge pull request #30549 from Calinou/improve-2d-raycast-oneway-drawing
Improve 2D RayCast and one-way collision drawing
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/collision_shape_2d.cpp | 22 | ||||
-rw-r--r-- | scene/2d/ray_cast_2d.cpp | 19 |
2 files changed, 22 insertions, 19 deletions
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index 5440a1d8c3..f79d79d039 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -97,15 +97,8 @@ void CollisionShape2D::_notification(int p_what) { } owner_id = 0; parent = NULL; - } break; - /* - case NOTIFICATION_TRANSFORM_CHANGED: { - - if (!is_inside_scene()) - break; - _update_parent(); - } break;*/ + } break; case NOTIFICATION_DRAW: { if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) { @@ -131,10 +124,13 @@ void CollisionShape2D::_notification(int p_what) { rect = rect.grow(3); if (one_way_collision) { - Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4); - dcol.a = 1.0; + // Draw an arrow indicating the one-way collision direction + draw_col = get_tree()->get_debug_collisions_color().inverted(); + if (disabled) { + draw_col = draw_col.darkened(0.25); + } Vector2 line_to(0, 20); - draw_line(Vector2(), line_to, dcol, 3); + draw_line(Vector2(), line_to, draw_col, 2, true); Vector<Vector2> pts; float tsize = 8; pts.push_back(line_to + (Vector2(0, tsize))); @@ -142,9 +138,9 @@ void CollisionShape2D::_notification(int p_what) { pts.push_back(line_to + (Vector2(-0.707 * tsize, 0))); Vector<Color> cols; for (int i = 0; i < 3; i++) - cols.push_back(dcol); + cols.push_back(draw_col); - draw_primitive(pts, cols, Vector<Vector2>()); //small arrow + draw_primitive(pts, cols, Vector<Vector2>()); } } break; } diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index 57dfe5176d..bf8d008bb2 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -100,6 +100,7 @@ Vector2 RayCast2D::get_collision_normal() const { void RayCast2D::set_enabled(bool p_enabled) { enabled = p_enabled; + update(); if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) set_physics_process_internal(p_enabled); if (!p_enabled) @@ -167,19 +168,25 @@ void RayCast2D::_notification(int p_what) { xf.rotate(cast_to.angle()); xf.translate(Vector2(cast_to.length(), 0)); - //Vector2 tip = Vector2(0,s->get_length()); - Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4); - draw_line(Vector2(), cast_to, dcol, 3); + // Draw an arrow indicating where the RayCast is pointing to + Color draw_col = get_tree()->get_debug_collisions_color(); + if (!enabled) { + float g = draw_col.get_v(); + draw_col.r = g; + draw_col.g = g; + draw_col.b = g; + } + draw_line(Vector2(), cast_to, draw_col, 2, true); Vector<Vector2> pts; - float tsize = 4; + float tsize = 8; pts.push_back(xf.xform(Vector2(tsize, 0))); pts.push_back(xf.xform(Vector2(0, 0.707 * tsize))); pts.push_back(xf.xform(Vector2(0, -0.707 * tsize))); Vector<Color> cols; for (int i = 0; i < 3; i++) - cols.push_back(dcol); + cols.push_back(draw_col); - draw_primitive(pts, cols, Vector<Vector2>()); //small arrow + draw_primitive(pts, cols, Vector<Vector2>()); } break; |