How do I make a moving WheelSpin Arrow?

  1. What do you want to achieve? Keep it simple and clear!
    I want the white arrow in the video to move when a reward passes under it like how it would in real life or in a 3D environment.

  2. What is the issue? Include screenshots / videos if possible!
    I’m using TweenService to achieve the current effect but it’s slow and breaks if the wheel goes too fast.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Here is what I have rn:

local lastAngle = 0
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 1, true)
local arrowTween = TweenService:Create(SpinFrame.Arrow, tweenInfo, {Rotation = -25})

Wheel:GetPropertyChangedSignal("Rotation"):Connect(function()
    if Wheel.Rotation - lastAngle >= 30 then
        lastAngle = Wheel.Rotation
        
        SoundService.ArrowHit:Play()
        arrowTween:Play()
    end
end)

1 Like

I made it work!

-- Variables
local arrowHitAngles = {25, 83, 143, 206, 268, 326}
local currentIndex = 1
local lastRealAngle = 0
local lastAngle = 0
local arrowTask;

-- Private Functions
local function _getAngle(targetAngle: number?): number
	local currentAngle = Loot.Rotation - math.floor(Loot.Rotation / 360) * 360
	
	return targetAngle and targetAngle - currentAngle or currentAngle
end

-- Runtime
local lastChangedTime = os.clock()

Loot:GetPropertyChangedSignal("Rotation"):Connect(function()
	local currentAngle, hitAngle = _getAngle(), nil
	local t = os.clock() - lastChangedTime -- Time [s]
	local theta = Loot.Rotation - lastRealAngle -- Angle Change [deg]

	currentIndex = table.find(arrowHitAngles, currentAngle) or currentIndex
	hitAngle = arrowHitAngles[currentIndex]
	
	if lastAngle < hitAngle and currentAngle >= hitAngle then
		if arrowTask then task.cancel(arrowTask); arrowTask = nil end

		local tweenIfo = TweenInfo.new(t * 30)
		local hitTween = TweenService:Create(SpinFrame.Arrow, tweenIfo, {Rotation = -25})
		local reverseTween = TweenService:Create(SpinFrame.Arrow, tweenIfo, {Rotation = 0})

		if SpinFrame.Visible then SoundService.ArrowHit:Play() end
		
		arrowTask = task.spawn(function()
			hitTween:Play()
			task.wait(t / theta * 10)
			reverseTween:Play()
		end)
		
		currentIndex = currentIndex <= 5 and currentIndex + 1 or 1
	end
	
	lastChangedTime = os.clock()
	lastRealAngle = Loot.Rotation
	lastAngle = currentAngle
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.