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

How can I include Position and Rotation in a CFrame?

Asked by
N43FGXL 169
4 years ago
Edited 4 years ago

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...
0
CFrame.new(x,y,z,rx,ry,rz) Mr_m12Ck53 105 — 4y

1 answer

Log in to vote
1
Answered by
Nanomatics 1160 Moderation Voter
4 years ago

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.

0
Please use CFrame.Angles Ziffixture 6913 — 4y
Ad

Answer this question