Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using a FrameObject to Connect 2 Vector2 Points? (closed)

Asked by
x_Tso 48
5 years ago
Edited 5 years ago

Hi! Currently I'm attempting to use a frame to connect the origin of 2 other frames (which will later be used for my first draft at detecting collision with circular UI.)

So I have the code working almost totally okay, my only issue with this line-drawing function is it's positioning (from what I can tell, at least.)

Here's the function:

local p1 = script.Parent.Icon.AbsolutePosition + script.Parent.Icon.AbsoluteSize/2
local p2 = script.Parent.Bullet_Circle.AbsolutePosition + script.Parent.Bullet_Circle.AbsoluteSize/2

local line = script.Parent.Parent.LineDraw
local size = UDim2.new(0, ((p2.X - p1.X)^2 + (p2.Y - p1.Y)^2)^0.5, 0, 1)
local position = UDim2.new(0, (p1.X + p2.X)/2, 0, (p1.Y + p2.Y)/2)
local rotation = math.atan2(p2.Y - p1.Y, p2.X - p1.X) * (180 / math.pi)

It's supposed to connect the edges of the line at the origin of the 2 collision frames.

Upon spawning, it looks like the line is centered position-wise on the center of the player icon. Upon moving, it definitely isn't staying centered and I can't find a clear pattern of it's movement and what it's basing the position around.

Here's how I'm setting the properties of this frame:

line.Position = UDim2.new(0, midpoint.X, 0, midpoint.Y)
line.Size = size
line.Rotation = rotation

Any ideas what's going on?

Here's a picture of what's happening, if that helps. I'll make a video too in a second.

1 answer

Log in to vote
0
Answered by
x_Tso 48
5 years ago

solution: anchor point set to (0.5, 0.5)

Ad

Answer this question