Skip to content

Cannot set spring velocity and position in the same frame #435

@Raild3x

Description

@Raild3x

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    brokenSomething isn't rightready to work onEnhancements/changes ready to be made

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions