Help with an image drawing???

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

Hello!
How can I have an arrow draw from one object to another object, in other words, I click object 1 and it draws the arrow from object 1 to object 2. See the 1st image to know what I mean.

Also., I have these 2 images for what will be the arrow

enter image description here

enter image description here

Please help?

:bust_in_silhouette: Reply From: kidscancode

I just did something like this in a recent project. I found it easier to use custom drawing rather than images, although you should also be able to do something with Line2D using textures.

Here’s the code - it breaks down into two parts, the dashed line and the arrow:

func draw_arrow_dashed(start, end, size, color):
	# draw dashed line
	var dir = (end - start).normalized()
	var dist = (end - start).length()
	var dash = dir * dist / 10  # segment size
	var gap = dir * dist / 20  # gap size
	var n = 0
	var pos = start  # drawing position
	var points = PoolVector2Array()
	while n < dist:
		draw_polyline(PoolVector2Array([pos, pos + dash]), color, size, true)
		pos += dash + gap
		n += dash.length() + gap.length()
	# draw triangular arrow end
	var a = end + dir * size/1.5 
	var b = end + dir.rotated(2*PI/3) * size
	var c = end + dir.rotated(4*PI/3) * size
	draw_polygon(PoolVector2Array([a, b, c]), PoolColorArray([color]))

It looks like this in-game:

enter image description here