Weird inconsistency with animation - heartbeat

I’ve written a script to animate a lootbox, the code runs something like this:

function SpinObjects:Move(distToMove)
	self.Position = self.Position + distToMove
	if self.Position > END_POSITION then
		self:Destroy()
		SpinObjects.new(OutfitDataManager.GetRandomOutfitWithRarity(3), MostRecent.Position - (PADDING + FRAME_SIZE))
	else
		self:SetFramePosition()
	end
end
 

function SpinObjects:SetFramePosition()
	self.Frame.Position = UDim2.new(self.Position, 0, 0.5, 0)
end


local heartbeatBind = RunService.Heartbeat:Connect(function(dt)
		local distToMove = dt * SPEED
		for object, _ in pairs(LiveObjects)do
			object:Move(distToMove)
		end
	end)
end)

So its pretty simple, it just moves everything along every heartbeat. SPEED is defined as the speed it should be travelling every second, so doing dt * SPEED is legit, no need for a /60 in there.

However, I get this stutter which makes it hideous

I thought at first maybe the animation hadn’t finished before the next heartbeat, but that wasn’t the case. Any help would be much appreciated

1 Like

Hi,

Have you tried using the TweenService with the different elements on the screen? It might mean you’ll have to reconfigure a couple of things, but Tweening across the screen in a linear fashion and then moving it back to the left when the rotation is complete would work I believe.

Might as well give it a shot.

Hope this helps,
-Tom :slight_smile:

1 Like

The inconsistency was because of the expensive :Clone() operation, but I changed to this anyway to simplify it