Buttery smooth tweening because I was bored and want to flex my math skills :D [Drop some suggestions if you want]

I got incredibly bored after finals last week and was looking for something to do, and I like making things on this app since I know coding pretty well. But anyways here is the code if you want to copy it, this took me like 15 minutes to make, so you can use this for whatever you’d like. No attribution or credit required, I’m not stingy about that lol. Btw, this just makes it rotate a bit and change size, just made it because I was bored.

With Orientation Change

local RunService = game:GetService("RunService")
local logo = script.Parent

local baseSize = logo.Size
local baseRotation = 0

local pulseAmplitude = 0.08
local pulseSpeed = 1.5

local rotateAmplitude = 3
local rotateSpeed = 0.5

local startTime = tick()

local function precise(val, decimals)
	local mult = 10 ^ decimals
	return math.floor(val * mult + 0.5) / mult
end

local function getScale(t)
	local sineValue = math.sin(t * math.pi * pulseSpeed)
	local scale = 1 + sineValue * (pulseAmplitude / 2)
	return precise(scale, 9)
end

local function getRotation(t)
	local rotationValue = math.sin(t * math.pi * rotateSpeed)
	local rotation = baseRotation + rotationValue * rotateAmplitude
	return precise(rotation, 9)
end

local function applyScale(scale)
	return UDim2.new(
		baseSize.X.Scale * scale,
		baseSize.X.Offset,
		baseSize.Y.Scale * scale,
		baseSize.Y.Offset
	)
end

RunService.RenderStepped:Connect(function()
	local currentTime = tick() - startTime

	local scaleFactor = getScale(currentTime)
	local rotation = getRotation(currentTime)

	logo.Size = applyScale(scaleFactor)
	logo.Rotation = rotation
end)  

No Orientation Change [On Hover]

local RunService = game:GetService("RunService")
local button = script.Parent
local label = button:WaitForChild("Text")

local baseSize = button.Size
local baseTextSize = label.TextSize
local pulseAmplitude = 0.08
local pulseSpeed = 1.5
local hovering = false
local startTime = 0

local function precise(val, decimals)
	local mult = 10 ^ decimals
	return math.floor(val * mult + 0.5) / mult
end

local function getScale(t)
	local sineValue = math.sin(t * math.pi * pulseSpeed)
	local scale = 1 + sineValue * (pulseAmplitude / 2)
	return precise(scale, 9)
end

local function applyScale(scale, base)
	return UDim2.new(
		base.X.Scale * scale,
		base.X.Offset,
		base.Y.Scale * scale,
		base.Y.Offset
	)
end

button.MouseEnter:Connect(function()
	hovering = true
	startTime = tick()
end)

button.MouseLeave:Connect(function()
	hovering = false
	button.Size = baseSize
	label.TextSize = baseTextSize
end)

RunService.RenderStepped:Connect(function()
	if hovering then
		local t = tick() - startTime
		local scale = getScale(t)
		button.Size = applyScale(scale, baseSize)
		label.TextSize = baseTextSize * scale
	end
end)

3 Likes

ok, but whats the difference with tweenservice

2 Likes

show video grr auguaghagha

1 Like

I gotchu man, mb for the bad quality, js does something like this, really smooth

Well you kinda need the tween service, the math just makes it smoother by bringing the percentages down to like a billionth, it’s not really that advanced, just a quick script fr