Drawing a 2D line between two points using Scale

Hello!
I am currently scripting a rhythm game. Whenever you play a song, it will first load the song map (a module). I have the normal notes working, but the problem I am facing is the hold notes.

I have two points, the note, and the tail note. Both of these points are ImageLabels. What I am trying to achieve is to make a line (frame) that goes between the two points.

Rotation isn’t needed but can be helpful in case I add something later.

I looked for so many possible solutions but they all don’t seem to work out as the line appears in random positions off the screen. Remember that I want this in scale, NOT Offset

I don’t need code, I just want logic. However, code may be useful.

You can do this by subtracting the position from the lowermost object from the uppermost one, then setting the position to the uppermost object.

Screen Shot 2021-08-07 at 7.27.36 PM

local lower = script.Parent.Lower
local upper = script.Parent.Upper

local function drawLine()
	local line = Instance.new('Frame')
	line.Parent = script.Parent
	line.Position = upper.Position
	line.Size = lower.Position - upper.Position
end

drawLine()

line.rbxm (2.7 KB)

It isn’t exact… but it does the trick! I just made some offsets to get line in the middle. Thanks!

That’s because you have to use the AnchorPoint property. You can either set the AnchorPoint of the line to 1,0 and set its size to 0,0,x - (dot.Size.Y / 2),0 or set the AnchorPoint of the dots to 0.5,0.5 (which would probably be easier :wink: )

I set the anchor point of the points to 0.5, 0.5 and it works perfectly! Thank you :slight_smile:

1 Like

I hope your rhythm game works out in the end, might play it when it is done

1 Like