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

How Do You Match Position and Rotation of Another Part Using CFrame?

How do you make Part1 have the same rotation and position as Part2 using CFrame?

Note: Part1's rotation is not always (0, 0, 0)

local Part2 = workspace.Part2

script.Parent.CFrame = CFrame.new(Part2.Position) * CFrame.Angles(math.rad(Part2.Orientation.X), math.rad(Part2.Orientation.Y), math.rad(Part2.Orientation.Z))

The code above only positions Part1 correctly, but the rotation is way off...

1 answer

✓ Accepted answer

A CFrame consists of a rotation matrix and a position vector. If you want a part to match both the position and rotation of another part, just set their CFrames to be the same.

local Part2 = workspace:WaitForChild("Part2")

script.Parent.CFrame = Part2.CFrame

Hope this helps! :)

1 comment

0

Oh wow, thanks!

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