How do I have line2D drawn on screen to collide with other objects?

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

Hi community,
I’m completely new to godot. I wanted to build a game similar to Happy Glass ( which player can draw lines on the screen and existing objects would be able to collide/interact with the lines.

I’ve came to the position where I can draw lines on screen now with the script below:

func _input(event):
	if event is InputEventMouseButton:
		_pressed = event.pressed
		if _pressed:
			_current_line =
	if event is InputEventMouseMotion && _pressed:
	if event is InputEventMouseButton && !_pressed:

However, my other objects are not interacting with the lines. I know I need to add CollisionBody or something but I can’t figure out how.

Thanks so much

:bust_in_silhouette: Reply From: kidscancode

You need to iterate through the points of the Line2D and add SegmentShape2D collisions to each pair of points.

Here’s an example:

Thank you! This works but I need to figure out a way to make it apply the collision while I’m drawing. currently only works after I’m done drawing.

ohpoloha | 2023-06-28 18:46