Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Find (square/retangular) size between two points?

I'm currently creating a script that finds the center location between two points**(parts)** and creates a part that is positioned to the center position, and I'm also trying to make it so that it resizes the part to make it so that it covers both Point A and Point B, but I can't seem to figure out how to find the retangular/square size between both of them to cover them both. Here's my script:

local Point1 = workspace.Point1
local Point2 = workspace.Point2

local MidPoint = Instance.new("Part", workspace)
MidPoint.Name = "MidPoint"
MidPoint.Transparency = 0.5
MidPoint.Anchored = true

MidPoint.Position = (Point1.Position:Lerp(Point2.Position, 0.5)) -- works perfectly fine, part is moved to the center
MidPoint.Size = Vector3.new((Point1.Position + Point2.Position).Magnitude) -- part becomes a thin line instead of a square/rentagle that covers both points. I really don't know how to find the proper size

1 comment

0

Hi, could you mark my answer as a solution if it worked, or give feedback?

1 answer

The size is simply the difference in position between the two parts. Which is to say the offset but in absolute terms calculated like so:

function calculateSize(part1, part2)
	local pos1, pos2 = part1.Position, part2.Position
	local x, y, z = math.abs(pos2.X - pos1.X), math.abs(pos2.Y - pos1.Y), math.abs(pos2.Z - pos1.Z)
	return Vector3.new(x,y,z)
end

If you aren't very familiar with vectors, here's some reading:

Basics In relation to Roblox

1 comment

0

Do note that the size is calculated from the centres of the parts! This means that the created part will only be as thick as the difference in Y-values between these two!

This discussion is preserved as it was. New answers, comments, and votes are closed.