allow changing the current value of a spring (similar to sources) (#36)

* allow changing the current value of a spring (similar to sources)

* use spaces instead of tabs for identing
This commit is contained in:
EwDev 2024-09-11 11:11:47 +02:00 committed by GitHub
parent fbe2f01bb9
commit 83db00a073
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -201,10 +201,28 @@ local function spring<T>(source: () -> T, period: number?, damping_ratio: number
-- set output to goal -- set output to goal
output.cache = data.source_value output.cache = data.source_value
return function() return function(...)
if select("#", ...) == 0 then -- no args were given
push_child_to_scope(output) push_child_to_scope(output)
return output.cache return output.cache
end end
-- set current position to value
local v = ... :: T
data.x0_123, data.x0_456 = type_to_vec6[typeof(v)](v)
-- reset velocity
data.v_123 = ZERO
data.v_456 = ZERO
-- schedule spring
springs[data] = output
-- set output to value
output.cache = v
return v
end
end end
local function step_springs(dt: number) local function step_springs(dt: number)