Can u add collisions to a line

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

Question is simple. Can u add collisions to a line thet’s drwan by draw_line function

:bust_in_silhouette: Reply From: exuin

Yes, but you will have to make your own collision shape and place it where the line is. Lines do not just have collision on their own.

:bust_in_silhouette: Reply From: scrubswithnosleeves

Yes here is a code snippet that I use to basically do that, excepts with a raycast and line2D node, but the principle is the same.

if raycast.is_colliding():
		var coll_point = raycast.get_collision_point()
		laser.points[1] = to_local(coll_point)
		particles.global_position = coll_point
		var shape =
		var half_way_amount = (global_position - coll_point)/2.0
		var center_point = global_position - half_way_amount
		shape.extents.x = half_way_amount.rotated(rotation).x
	    $CollisionShape2D.shape = shape