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

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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! :)

0
Oh wow, thanks! GatitosMansion 187 — 5y
Ad

Answer this question