How do you make a randomized smooth spin script?

Self explanatory via the title, my goal is to find randomization in spinning so that the ring of the ball that you can see in the gyazo I will show you has some skillset in it.

https://gyazo.com/6701ae02afbab9289ecb10e791cccdaa

Yes, there are a lot of “randomized” spin scripts, but each have been unsmooth and just barely configurable.

If you have any good code for this, let me know! :slight_smile:

If you want this sort of smooth effect, you should use some kind of Spring library to achieve the movement goal in a way where it is interpolated nicely.

A good library for this kind of work is spr by Fractality - you would set the rotation goal randomly (via CFrame.Angles(randX, randY, randZ) and then use the spring library to go to that goal. This will mean it will not suddenly move, and instead will interpolate the target change in the way you want.

I’ve no idea how to properly use this - even with reading everything. If you could help out a little further, that would be appreciated.

Sure - here is some pseudocode I drew up for how you might want to do this. I can’t write the thing for you but hope it helps.

local spr = require(script.spr) -- spr module
local Ball = workspace.Ball -- The ball you want to rotate
local Rand = Random.new(os.time()) -- The random number generator, seeded properly

while wait(RandNextNumber(1,3)) do
   spr.target(Ball, 1, 1, { -- Change the goal orientation
    Orientation = Vector3.new(
      Rand:NextNumber(0,360), 
      Rand:NextNumber(0,360), 
      Rand:NextNumber(0,360)
    )
})
end
1 Like

Hey, thanks, but it comes up as this error in the Dev Console:

image

I’m not sure if the code is missing a variable as such;

image

1 Like

RandNextNumber is not a feature that comes with lua itself, but math.random is.

local spr = require(script.spr)
local Ball = workspace.Ball
local Rand = Random.new(os.time())

while wait(math.random(1,3)) do
   spr.target(Ball, 1, 1, {
    Orientation = Vector3.new(
      Rand:NextNumber(0,360), 
      Rand:NextNumber(0,360), 
      Rand:NextNumber(0,360)
    )
})
end
1 Like

I think unix meant Rand:NextNumber(1,3)