Hello,
How do I make a part randomly rotate.
Iv'e been trying to figure this out for a while yet haven't found any tutorials of scripting help.
Help would be much appreciated.
Thank you
Hello,
How do I make a part randomly rotate.
Iv'e been trying to figure this out for a while yet haven't found any tutorials of scripting help.
Help would be much appreciated.
Thank you
This script will randomly rotate the part, and ensure that it doesn't change its position if it happens to be inside another part:
local part = game.Workspace.Part
while true do
wait(1)
local X = math.rad(math.random(360))
local Y = math.rad(math.random(360))
local Z = math.rad(math.random(360))
part.CFrame = CFrame.new(part.Position) * CFrame.Angles(X, Y, Z)
end
It's a little complicated, but if you need an explanation, be sure to leave a comment.
This is a more simple script that won't account for when the part is inside of another part:
local part = game.Workspace.Part
while true do
wait(1)
local X = math.random(360)
local Y = math.random(360)
local Z = math.random(360)
part.Orientation = Vector3.new(X, Y, Z)
end
math.random(360) returns a random whole number ranging from 1 - 360(inclusive).
--This is pretty simple
local Part = workspace.BPart -- Get the part
local RadRotation = math.random(10, 50) --Make a random rotation value
Part.Orientation = Vector3.new(RadRotation, RadRotation, RadRotation) --- Rotate the part
that goes in 1 direction since the same random is for X and Y and Z
yeah you could separate the values.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Theres actually two arguments of "math.random". In this case, use "math.random(0, 360)".