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

How do I set Primary Part Orientation?

Asked by 4 years ago
Edited 4 years ago

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?

0
Hey, I'm having his problem too. If only you wold get an answer nc2r 117 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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

0
Thank you so much! Cynical_Innovation 595 — 4y
0
No problem. :) GeneratedScript 740 — 4y
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 Cynical_Innovation 595 — 4y
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)) GeneratedScript 740 — 4y
0
I have defined the parts. It still does the same thing. Cynical_Innovation 595 — 4y
Ad

Answer this question