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

Questions about using Model:SetPrimaryPartCFrame()?

So I learned about Model:SetPrimaryPartCFrame() and I have questions about using it. The way im it in a script is like this:


local Model = script.Parent

Model:SetPrimaryPartCFrame(Model:GetPrimaryPartCFrame() * CFrame.new(0,0,0))

But I was wondering, how do you directly SET the position and orientation? This script just moves the part but how would I move it to a position and set its orientation?

1 comment

0

you do that... by giving it a CFrame. this has less to do with the function itself, you should find out how to make a CFrame the way you want to. @0hsa has a good example.

2 answers

✓ Accepted answer
Model:SetPrimaryPartCFrame(Model.PrimaryPart.CFrame * CFrame.new(0, 0, 0) * CFrame.fromEulerAnglesXYZ(0, math.rad(90), 0)) --[[ would turn it 90 degrees ]]

:SetPrimaryPartCFrame() is equivalent to setting the CFrame of a part like so:

part.CFrame = CFrame.new()

The difference is that it does it to whatever the primary part of the model happens to be.

I think what you're asking for is how you can change positions and orientations of parts, and this is where CFrames come in. To put it simply, CFrames are information on the position and orientation of parts. You can get a part's position, orientation etc. as well as do math with them, with the help of CFrames.

They do require a bit of math knowledge, but the basics should be relativity easy to understand. Here is the API reference for CFrames that I would suggest to take a look at: https://developer.roblox.com/en-us/api-reference/datatype/CFrame

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