I have 2D laser beam.
Its simple Sprite node with rotation & scale on Y and RayCast2D as child node to find hit & cut beam at hit position (via scaling on y : (collision - pos).length()).
So far everything is good and working.
But, when player get out of laser reach and laser is still firing, sayd laser is "cut" in middle of screen, which doesnt look good. Its laser, you know, one does not simply cut laser beam :)
screenshot on google drive
So i added VisibilityNotifier2D, moving it at the end of beam (again, its only pos.Y in local space) and multiply pos.Y every time
get_node("VisibilityNotifier2D").is_on_screen() returns true, like this:
# inside _process()
# variables _laser_is_colliding and _laser_colliding_at are from _fixed_process()
# variable laser_reach is how far laser beam can hit anything (also hint for AI to look for enemies max away)
# laser_ray is Sprite node and laser_hit_effect is Sprite node with some fx to hide flat laser end
var collision_length = (_laser_colliding_at - get_global_pos()).length()
laser_hit_effect.set_pos(Vector2(0, collision_length + 25))
# do-while missing...
var c = 2
laser_end_visible.set_pos(Vector2(0, laser_reach * c))
print(str('local pos: [', Vector2(0, laser_reach * c), '] global pos: [',laser_end_visible.get_global_pos(), '], is_on_screen:', laser_end_visible.is_on_screen()))
laser_ray.set_scale(Vector2(1, laser_reach * c))
c = c + 1
laser_end_visible.is_on_screen() is returning true forever, even when his pos is far outside possible Camera2D position (say, 10k px on both axis, still
.is_on_screen() is true).
So i think, i have to call some "update" func... or... something... I am really hoping visibility tests are computed and not done as rendering some color and checking it :) But i have no idea which func to call. I tried to peek at VisibilityNotifier2D source code, but i cant find anything.
Edited: formatting issues & typo