Simple Randomised EasingStyle Module

Ever wanted to add some randomised spice to your games? Well I did for approximately 5 minutes before I realised a customer wouldn’t like a product with random tweens.

Anyway, this module returns a completely random EasingStyle for your tweens, instead of the usual boring ones you may have.

This doesn’t really serve a huge purpose, however it’s quite cool!

Code
local module = {}

function module:getRandomTweenMethod(): Enum.EasingStyle
	local easingStyles = {
		Enum.EasingStyle.Linear,
		Enum.EasingStyle.Sine,
		Enum.EasingStyle.Quad,
		Enum.EasingStyle.Cubic,
		Enum.EasingStyle.Quart,
		Enum.EasingStyle.Quint,
		Enum.EasingStyle.Exponential,
		Enum.EasingStyle.Circular,
		Enum.EasingStyle.Back,
		Enum.EasingStyle.Bounce,
		Enum.EasingStyle.Elastic

	}
	
	math.randomseed(os.time())
	
	local style = easingStyles[math.random(1, #easingStyles)]
	
	return style
end


return module

2 Likes

why not:

function getRandomStyle(): Enum.EasingStyle
  local styles = Enum.EasingStyle:GetEnumItems()
  math.randomseed(os.time())

  return style[math.random(1, #styles)]
end

this way you don’t create an array every time the fn is called + your code is shorter!

7 Likes

Another version for slightly better performance:

local EasingStyles = Enum.EasingStyle:GetEnumItems()
local EasingCount = #EasingStyles
local gen = Random.new(os.clock() * 2048)

local function NextStyle()
    return EasingStyles[gen:NextInteger(1, EasingCount)]
end

Also… why would we use a random easing style? :sweat_smile:

Oh…

5 Likes

Oh wow I never knew you could do the GetEnumItems() method! Thanks for telling me, I originally tried to do that but tried a GetChildren method.

2 Likes

It’s not a huge improvement, it’s just something cool you could add to make your game slightly more interesting and random?

What if you had an elevator that tweened up and down, and instead of the usual Linear and Sine methods, maybe it was Elastic or Expn. !

1 Like