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

How to randomize part orientation?

Asked by 4 years ago

I am using tweenservice to rotate a part when a specific action occurs. The part does rotate, but it rotates in the same direction instead of random directions each time. How do I properly randomize orientation?

local tweeninfo = TweenInfo.new(1)
ts = game:GetService("TweenService")
local goal = {}
goal.Size = Vector3.new(0, 0, 0)
goal.Orientation = Vector3.new(math.random(-90,90),math.random(-90,90),math.random(-90,90))

1 answer

Log in to vote
0
Answered by 4 years ago

Use CFrame.Angles. Here's an example;

goal.CFrame = part.CFrame * CFrame.Angles(math.rad(math.radnom(-180,180)),math.rad(math.radnom(-180,180)),math.rad(math.radnom(-180,180)))

math.rad() just converts the numbers to radians.

Ad

Answer this question