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

How do i get the position between two parts and the size needed to fill the hole between it?

script.Parent.ClickDetector.MouseClick:Connect(function()
	if workspace.Head.Position.Z == 27.5 then return end
	local z = workspace.Head.Position.Z - 1
	local s = z + 34.5 / 2
	local w = s - z
	workspace.Neck.Size = Vector3.new(2,2,s)
	workspace.Neck.CFrame = CFrame.new(-32, 5, w)
	workspace.Head.CFrame = CFrame.new(-32, 5, z)
end)

the math won't work, i need to make it so that it goes in the middle of the two parts and then make it's size long enough to fill the gap between the two parts.

2 comments

0

#Math

0

can you explain a bit more on what you are trying to do here, because I see you are using Z with head and neck which is a bit weird. If you are trying to get the height then you need to use Y element of Position.

1 answer

✓ Accepted answer

To achieve this, I would use a combination of raycasting and Magnitude.

First of all, I would fire two rays, one from the position of the first part to the second, and one in the reverse. This would tell you the location of the edge of both parts (on the face)

Secondly, you can get the difference between the two edges and divide it by 2 to get the middle point. From there, you can get the magnitude between the points for the size.

For example:

local function GetPoint(Part1,Part2)
	local R = Ray.new(Part1.Position, (Part2.Position - Part1.Position).unit*999)
	local Part,Pos = workspace:FindPartOnRayWithWhitelist(R,{Part2})
	return Pos
end

local function GetPosAndSizeBetweenParts(Part1,Part2)
	local Pos1 = GetPoint(Part2,Part1)
	local Pos2 = GetPoint(Part1,Part2)
	local MiddlePosition = Pos1 + (Pos2 - Pos1)/2
	local Size = (Pos2 - Pos1).Magnitude
	return MiddlePosition,Size
end

local Position, Size = GetPosAndSizeBetweenParts(enterpart1here, enterpart2here)
print(Position,Size)

Keep in mind this isn't tested and likely will error, but it might work as an outline.

Hope this helps!

1 comment

0

thanks!

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