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 set Primary Part Orientation?

So whenever I teleport the model, It turns to the right. I don't want that happening. So how do I Set a Primary Part Orientation? Here's the code:

--Variables
local Echo = script.Parent
--Positions
wait(10)
script.Parent:SetPrimaryPartCFrame()(Vector3.new(1.67, 3.054, 44.89))
Echo.Shutter:Play()	
wait(10)
script.Parent:SetPrimaryPartCFrame(CFrame.new(3.966, 3.054, 44.89))
Echo.Shutter:Play()

Any ideas?

1 comment

0

Hey, I'm having his problem too. If only you wold get an answer

1 answer

✓ Accepted answer

There are a few things wrong. First, SetPrimaryPartCFrame() doesn't work like that. It works like this: model:SetPrimaryPartCFrame(CFrame.new()). It has to go inside the parentheses. Second, CFrame.new() accepts 2 main Vector3s: Position and LookVector.

An example: Lets say you want to move Part1 to Part2 and have it face Part3:

Part1.CFrame = CFrame.new(Part2.Position, Part3.Position); -- it will teleport to Part2's position but face towards Part3's position.

Another example: Part1 teleports to origin and faces directly up.

Part1.CFrame = CFrame.new(Vector3.new(0, 0, 0), Vector3.new(0, 10, 0));

Now, you can also multiply a CFrame by CFrame.Angles(radX, radY, radZ) to rotate it. Keep in mind that CFrame.Angles() accepts radians only, so you can convert between degrees to radians VIA math.rad(degree).

For example, lets say we want to teleport Part1 to Part2 and rotate it 90 degrees. You can do this 2 ways:

Part1.CFrame = Part2.CFrame * CFrame.Angles(0, math.pi/2, 0); -- Rotate it 90 degrees on the Y axis

or

Part1.CFrame = Part2.CFrame * CFrame.Angles(0, math.rad(90), 0); -- same thing but using math.rad

Here are some resources to help you get started:

What are CFrames?

CFrame Math operations

Understanding CFrames

5 comments

0

Thank you so much!

0

No problem. :)

0

One thing though. I noticed that when I did Part1.CFrame = CFrame.new(Part2.Position, Part3.Position); , an error popped up. Why is that? Everything else works btw

0

You haven't defined the parts. You can fix this by defining them (local Part1, Part2, Part3 = workspace.Part1, workspace.Part2, workspace.Part3) or add workspace. right in front of each usage of 'Part'. (so like workspace.Part1.CFrame = CFrame.new(workspace.Part2.Position, workspace.Part3.Position))

0

I have defined the parts. It still does the same thing.

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