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

How to add rotation to a CFrame?

Asked by 7 years ago
Edited 7 years ago

I have an model, and I need to get a random rotation,

Local model = --whatever model
local cFrame = CFrame.new(0,0,0)--the CFrame is obtained through other calculations

local randonRotation = math.rad(math.random(1, 360))

--This is an imaginary scenario
cFrame:AddRotation(randonRotation , 0, 0)

model :SetPrimaryPartCFrame (cFrame)

so the model is going to have a random rotation in X axis, but I don't know how to add the rotation.

Any help would be appreciated.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You can use the CFrame.Angles constructor to add rotation to your CFrame :)

local model
local _CFrame = CFrame.new(0,0,0)

--rotated on the 'x' axis
local randomRotation = CFrame.Angles(math.rad(math.random(1, 360)),0,0)

local rotatedCFrame = _CFrame * randomRotation

model:SetPrimaryPartCFrame(rotatedCFrame)
0
Thanks, I already test and work good LordSalchipapas 96 — 7y
Ad

Answer this question