Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Cannot set spring velocity and position in the same frame

Open Raild3x opened this issue 4 months ago • 0 comments

I have the following code being used to make a level bar increase:

RunService.RenderStepped:Connect(function(dt)
	local targetLevel = peek(level)
	if peek(displayLevel) < targetLevel then
		displayProgress:set(1) -- instantly fill bar
		if peek(displayProgressSpring) >= 0.999 then
			displayLevel:set(peek(displayLevel) + 1)
			displayProgressSpring:setVelocity(0)
			displayProgressSpring:setPosition(0)
			print(`Level up! New level: {peek(displayLevel)}`)
			if peek(displayLevel) < targetLevel then
				displayProgress:set(1)
			else
				displayProgress:set(peek(expProgress))
			end
		end
	else
		displayProgress:set(peek(expProgress))
	end
end)

Flipping the position of these lines results in wildly different behavior:

displayProgressSpring:setVelocity(0)
displayProgressSpring:setPosition(0)

https://gyazo.com/84d2812465f796350caa380dd9fa5af8

displayProgressSpring:setPosition(0)
displayProgressSpring:setVelocity(0)

https://gyazo.com/a80565eced573091b1b22b254118de7c

I believe this results because setVelocity and setPosition override each other's _activeStart Values :setVelocity

self._activeStartP = table.clone(self._activeLatestP)
self._activeStartV = unpackType(newValue, newType)

:setPosition

self._activeStartP = unpackType(newValue, newType)
self._activeStartV = table.clone(self._activeLatestV)

Raild3x avatar Oct 23 '25 14:10 Raild3x