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

This commit is contained in:
ewd3v 2024-08-31 20:53:09 +02:00
parent fbe2f01bb9
commit c73cc4bc39
No known key found for this signature in database
GPG key ID: 18FF74D0F35B288C

View file

@ -201,9 +201,27 @@ 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(...)
push_child_to_scope(output) if select("#", ...) == 0 then -- no args were given
return output.cache push_child_to_scope(output)
return output.cache
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 end