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

How do I make a part that matches both the position and the rotation of another object?

Asked by 9 years ago

So, I have a part I want to clone and I want to position it inside another part and have that same part's rotation. Here's an example:

local clone = game.Workspace.Part:Clone()
clone.Parent = game.Workspace
clone.Position = Vector3.new(game.Workspace.Part2.Position)
clone.Rotation = Vector3.new(game.Workspace.Part2.Rotation)

Doing the above won't work, because it doesn't change the rotation and the position of the cloned part is above the part I want it to be in, not inside. Can anyone help me out?

0
Are you sure it is Vector3 or is it CFrame? Mystdar 352 — 9y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You just need to use CFrame, as it preserves rotation and allows objects to move through other objects.

Format:

part1.CFrame = part2.CFrame

Edit: exact code I used

local clone = game.Workspace.Part:Clone()
clone.Parent = game.Workspace
clone.CFrame = game.Workspace.Part2.CFrame
0
That does the positional part of what I need, but the rotation doesn't change. whyOmustOitObeOme 7 — 9y
0
It works perfectly when I test it. I edited my post with the exact code i used. Perci1 4988 — 9y
0
Try rotating part2 and then testing it. You'll notice the rotation of part stays the same, regardless of part2's rotation. whyOmustOitObeOme 7 — 9y
Ad

Answer this question