Randomly Revolving Cube

So I am trying to make a cube that spins randomly like Revolution cube in Epic minigames, and [Gone to Experimental] Cube Simulator - Roblox.

I tried searching, taking models, and none of them worked. Please help

1 Like

check this model out, similar to what you want it but in a mini scale

2 Likes

It works perfectly fine when it was normal, but when i size it up, It didn’t work. Any fixes here?

2 Likes

Increase the value of the gyro mover idk what that is but also decrease the density of the floating cube and i think that should resolve
Edit: It’s not mine actually Stickmasterluke made it for free but i just made a save for my self and put it to public

2 Likes

This might not be necessary if that model works, but here it is anyway.

local RunService = game:GetService("RunService")

local rotationDegPerSec = 5
local minWaitBetweenDirChange = 4
local maxWaitBetweenDirChange = 10

local partToRotate = -- the part you want to rotate

local rotationRadPerSec = math.rad(rotationDegPerSec)
local rotating = true

local attach0, attach1 = Instance.new("Attachment"), Instance.new("Attachment")
attach0.Parent, attach1.Parent = partToRotate, workspace.Terrain

local alignOri = 
Instance.new("AlignOrientation")
alignOri.RigidityEnabled = true
alignOri.Attachment0, alignOri.Attachment1 = attach0, attach1
alignOri.Parent = partToRotate

local alignPos = 
Instance.new("AlignPosition")
alignPos.RigidityEnabled = true
alignPos.Attachment0, alignPos.Attachment1 = attach0, attach1
alignPos.Parent = partToRotate

local nextDirChangeTick, rotVelocity

local function getRandNum()
    return math.random()*(-1)^math.random(1, 2)
end

local function changeTickAndDir()
    nextDirChangeTick = tick()+math.random(minWaitBetweenDirChange, maxWaitBetweenDirChange)
    local direction = Vector3.new(getRandNum(), getRandNum(), getRandNum()).Unit
    rotVelocity = direction*rotationRadPerSec
end


changeTickAndDir()

partToRotate.Anchored = false
attach1.CFrame = partToRotate.CFrame

local _, delta = nil, 0

while rotating do
    if tick() >= nextDirChangeTick then
        changeTickAndDir()
    end
    local rotChange = rotVelocity*delta
    attach1.CFrame *= CFrame.Angles(rotChange.X, rotChange.Y, rotChange.Z)
    _, delta = RunService.Stepped:Wait()
end
8 Likes

Thank you it works!! I appreciate it!

2 Likes

how will it work with a model?

1 Like

Well, if the other parts of the model are welded to the part being rotated, it should work.

I assume the same needs to be done when using the model you linked, because you mentioned bodygyro, which uses physics too.

1 Like

thanks anyway appreciated it man

1 Like

You could add a tween to this for a smooth transition when changing rotations