using { /Fortnite.com/Devices } using { /Verse.org/Simulation } using { /UnrealEngine.com/Temporary/SpatialMath } using { /UnrealEngine.com/Temporary/Diagnostics } spin_wheel_device := class(creative_device): @editable SpinButton: button_device = button_device{} # the player presses this @editable Wheel: creative_prop = creative_prop{} # the prop that spins @editable PrizeGranter: item_granter_device = item_granter_device{} # awards the prize @editable HopCount: int = 9 # 9 x 120deg = 3 full turns @editable SecondsPerHop: float = 0.18 # 120 degrees in radians — one safe, unambiguous third-of-a-turn. ThirdTurnRadians: float = 2.0943951 var IsSpinning: logic = false OnBegin(): void = SpinButton.InteractedWithEvent.Subscribe(OnButtonPressed) OnButtonPressed(Agent: agent): void = if (not IsSpinning?): spawn { SpinAndReward(Agent) } SpinAndReward(Agent: agent): void = set IsSpinning = true Position: vector3 = Wheel.GetTransform().Translation var Hop: int = 0 loop: if (Hop >= HopCount): break # Compose ONE more 120deg step onto the wheel's CURRENT orientation. # Each MoveTo target is only 120deg away -> every hop is an # unambiguous shortest-path move (the lesson's gotcha, applied live). CurrentRotation: rotation = Wheel.GetTransform().Rotation NextRotation: rotation = CurrentRotation.ApplyWorldRotationZ(ThirdTurnRadians) Wheel.MoveTo(Position, NextRotation, SecondsPerHop) set Hop = Hop + 1 PrizeGranter.GrantItem(Agent) set IsSpinning = false