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

How to add rotation to a CFrame?

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

✓ Accepted answer

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)

1 comment

0

Thanks, I already test and work good

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