0 votes

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
if _laser_is_colliding:
            var collision_length = (_laser_colliding_at - get_global_pos()).length()
            laser_ray.set_scale(Vector2(1, collision_length))
            laser_hit_effect.set_pos(Vector2(0, collision_length + 25))
            # do-while missing...
            laser_end_visible.set_pos(Vector2(0, laser_reach))
            #laser_end_visible.update() ????????????
            laser_ray.set_scale(Vector2(1, laser_reach))
            var c = 2
            while laser_end_visible.is_on_screen():
                laser_end_visible.set_pos(Vector2(0, laser_reach * c))
                #laser_end_visible.update() ????????????
                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

But 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

in Engine by (241 points)
edited by

1 Answer

0 votes
Best answer

Self answer after 3 days:

its known bug #1269.

by (241 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.