How do I script a part that rotates in random directions smoothly?

I’m trying to make a part rotate in random directions that rotates smooth and fluid, but I cant find a way.

Here is an example of what it looks like currently

Here is the code that I am using

local bullsquid = workspace:WaitForChild("bullsquid")

while true do 
	bullsquid.CFrame *= CFrame.Angles(math.random(), math.random(), math.random())
	wait(.2)
end

Here is an example of what I am trying to recreate

2 Likes

this should make the animations smoother!

local bg = nil
if bullsquid:FindFirstChild("BodyGyro") then
--it already is cloned
bg = bullsquid:FindFirstChild("BodyGyro")
else
bg = Instance.new("BodyGyro", bullsquid)
bg.MaxTorque = Vector3.new(400000, 400000, 400000)
end
while true do 
	bg.CFrame *= CFrame.Angles(math.random(), math.random(), math.random())
	wait(.2)
end
2 Likes

It does indeed work, however your code only works when the bullsquid is unanchored, I need the bullsquid to stay anchored in place.

Then we’ll have to use tweenservice!

local bullsquid = workspace:WaitForChild("bullsquid")
local tween = game:GetService("TweenService")
local bg = nil
while true do 
	
tween:Create(bullsquid,TweenInfo.new(0.2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out){CFrame =CFrame.Angles(math.random(), math.random(), math.random()) }):Play()
	wait(.2)
end
1 Like

An error happened, output log states
Workspace.bullsquid.Script:5: attempt to call a TweenInfo value

I seem to have fixed it by putting a comma where the CFrame is specified, however now it does not complete a full “spin” per se, here is what it looks like with the new code

It will look smoother if you reduce the yield time. You could also use sine and cosine, but it’s not really “random”.

local RunService = game:GetService'RunService'
local rad = math.rad
local clock = os.clock
local sin = math.sin
local cos = math.cos
local pi = math.pi
local Heartbeat = RunService.Heartbeat

local bullsquid = workspace:WaitForChild("bullsquid")

while true do
	local t = clock()
	local sine = sin(t) * 360
	local cosine = cos(t) * 360
	bullsquid.CFrame = CFrame.new(bullsquid.Position) * CFrame.Angles(rad(sine), 0, rad(cosine))
	Heartbeat:Wait()
end

Here’s what it looks like:

Use tween service and math.Random to select the vector3 stuff.

Is there a way to make this random?

You could try messing around with noise

local RunService = game:GetService'RunService'
local rad = math.rad
local clock = os.clock
local noise = math.noise
local random = math.random
local Heartbeat = RunService.Heartbeat

local bullsquid = workspace:WaitForChild("bullsquid")

local xseed = random(10000, 100000)
local yseed = random(10000, 100000)
local zseed = random(10000, 100000)
while true do
	local x = noise(xseed, clock() % 1000 * 0.5) * 360
	local y = noise(yseed, clock() % 1000 * 0.5) * 360
	local z = noise(zseed, clock() % 1000 * 0.5) * 360
	bullsquid.CFrame = CFrame.new(bullsquid.Position) * CFrame.Angles(rad(x), rad(y), rad(z))
	Heartbeat:Wait()
end

8 Likes

i have a simpler version just update the parts rotation with this on a renderstepped CFrame.Angles(0, math.rad(-360 * (tick() * 0.1- math.floor(tick() * 0.1))), math.sin(tick())/5)