the line is magnetized to the point

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Timofey

I want to create a laser, but the end of the line is magnetized to a certain point

extends RayCast2D

func _ready() -> void:
    $Line2D.points[0] = Vector2.ZERO
    $Line2D.points[1] = Vector2.ZERO

func _physics_process(_delta: float) -> void:
    if Input.is_action_pressed("LMB"):
    	enabled = true
    	look_at(get_global_mouse_position())
    	$Line2D.points[0] = position
    	var colPoint := get_collision_point()
    	print(colPoint)
    	$Line2D.points[1] = to_local(colPoint)
    else:
    	enabled = false
	    $Line2D.points[0] = Vector2.ZERO
	    $Line2D.points[1] = Vector2.ZERO

preview: https://drive.google.com/file/d/19LV5phdF3h7b4CGzePVmBgppk1x-wrY1/view?usp=sharing

:bust_in_silhouette: Reply From: exuin

If you look at the docs for get_collision_point() it says

Returns the collision point at which the ray intersects the closest object.

So since the edge of the cross is the closest object, the end of the line is stuck in it. You’ll probably just have to use another method.

I already understood that this is due to the length of the raycast

Timofey | 2021-02-27 14:01

So what do you want to do then?

exuin | 2021-02-27 14:05