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

How can I include Position and Rotation in a CFrame?

I'm trying to set the position and orientation of a model via the primary part.

local ClonedObS = workspace.Model

--Defined CFrames
local PositionCFrame = CFrame.new(1,5,19)
local OrientationCFrame = CFrame.fromEulerAnglesXYZ(math.rad(10), math.rad(1), math.rad(5))

ClonedObS:SetPrimaryPartCFrame(PositionCFrame, OrientationCFrame)) --This doesn't work for orientation

Is there a way I can set the position and orientation of a model in a CFrame?

ClonedObS:SetPrimaryPartCFrame(PositionCFrame)
ClonedObS:SetPrimaryPartCFrame(OrientationCFrame)
--Also doesn't work because it resets the previous CFrame

ClonedObS:SetPrimaryPartCFrame(OrientationCFrame)
ClonedObS:SetPrimaryPartCFrame(PositionCFrame)
--Same...

1 comment

0

CFrame.new(x,y,z,rx,ry,rz)

1 answer

You had it for the most part, you were just missing one little thing. We can add the orientation of a model just as if we are offsetting a CFrame.

For example, when you want to move something up by 5 studs you do:

part.CFrame = part.CFrame * CFrame.new(0, 5, 0) 

Same goes for orientation, so what you will need to do is:

local ClonedObS = workspace.Model

--Defined CFrames
local PositionCFrame = CFrame.new(1,5,19)
local OrientationCFrame = CFrame.fromEulerAnglesXYZ(math.rad(10), math.rad(1), math.rad(5))

local PosOrCFrame = PositionCFrame * OrientationCFrame --combining both

ClonedObS:SetPrimaryPartCFrame(PosOrCFrame)

That should work.

Hope I helped. If you have any questions please let me know.

1 comment

0

Please use CFrame.Angles

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