Rotate a part relative to another

Hello devs, I need to rotate a part if another is in a radius

As in if this part goes anywhere past these lines
image

the part below it will rotate to the same rotation with and offset of 90ish degrees

I don’t understand What you are trying to achieve could you provide a better description?

local radius = 4
local Part = script.Parent-- Instance.new("Part") -- change this with ur part

local ov = OverlapParams.new()
ov.FilterDescendantsInstances = {Part}

function lookAt(eye, target)
	local forwardVector = (target - eye).Unit
	local upVector = Vector3.new(0, 1, 0)
	-- You have to remember the right hand rule or google search to get this right
	local rightVector = forwardVector:Cross(upVector)
	local upVector2 = rightVector:Cross(forwardVector)

	return CFrame.fromMatrix(eye, rightVector, upVector2)
end

while true do
	task.wait()
	local parts = workspace:GetPartBoundsInRadius(Part.Position, radius, ov)

	if parts and parts[1] then
		local CF = lookAt(Part.Position, parts[1].Position)
		
		Part.CFrame = CF
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.