0 votes

my set up is a Sprite node, under the sprite node I have a ray cast 2D and a line 2D
Line2D has 2 points set up
And I have the following code :

onready var line = $Line2D
 onready var ray = $RayCast2D
 var hit_position := Vector2.ZERO
 var is_firing := false

 func _process(delta):
    if ray.is_colliding():
        if ray.get_collider() == target:
            is_firing = true
            hit_position = ray.get_collision_point()
        else:
            is_firing = false 
   if is_firing:
       fire_beam(hit_position)

func fire_beam(collision_point : Vector2):
    var local_pos = transform.xform_inv(collision_point)
    line.set_point_position(1,local_pos)

But when I run the line doesn't draw to the collision point.
I converted the collision position to local because I saw a youtube video which mentioned that it is in local space so I should draw it in local space.
And it is still not drawing to the collision point. I am not sure what I did wrong

asked Nov 13, 2019 in Engine by lowpolygon (164 points)

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.