I am trying to make a spin wheel (Wheel of Fortune or GTA V’s spin wheel for reference.) I have most of everything down, but I’m really struggling with getting the time between each peg so I can play a sound when the arrow “hits” it.
I’m no good at math, but I’ve tried my best to research stuff to find a solution. I tried finding out the revolutions per second and dividing that by the number of pegs to hopefully get the amount of time between each, but it didn’t work.
So far, everything I have tried either takes too little time or too long, so it completely misses the mark.
I watched a tutorial by @Sub2HTR to help start me off with the math for it, so I used his math to get the target angle of the wheel which is:
“Rewards” is a array of the wheel’s contents (which is 14, and is also the total number of pegs.)
local reward = math.random(1, #Rewards)
local angle = reward / #Rewards * 360 - (360 / #Rewards / 2)
local offset = -math.random() * 360 / #Rewards
local spins = math.random(0, 10) * 360
angle += offset + spins
local spinTime = Random.new():NextNumber(8, 20)
local tween = TweenService:Create(WheelBase, TweenInfo.new(spinTime, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
Rotation = Vector3.new(angle, 0, 0)
})
tween:Play()
and then, as I said, tried to find revolutions per second:
local revolutions = angle / 360
local waittick = (revolutions / spinTime) / #Rewards
local waitTime = waittick
and then I’m using a for loop to get the total amount of pegs that are passed while the wheel is turning toward its target angle to play the sounds
for i = 1, revolutions * #Rewards do
--waitTime = waitTime + waittick -- // Time gets bigger between each peg as it slows down via Quadratic (???) Not sure if I'm doing this correctly.
local sfx = script.tick:Clone()
sfx.Parent = WheelBase
sfx:Play()
game.Debris:AddItem(sfx, 0.7)
wait(waitTime)
end
I’m tweening this using Quadratic Interpolation, so I have no idea if that’s messing with it. I tried changing it to Linear to see for sure but it wasn’t working with Linear either. I’m completely lost. Some help would be super appreciated.