From c73cc4bc390e66e0c24b174f842a51acda11b054 Mon Sep 17 00:00:00 2001 From: ewd3v <74792428+ewd3v@users.noreply.github.com> Date: Sat, 31 Aug 2024 20:53:09 +0200 Subject: [PATCH] allow changing the current value of a spring (similar to sources) --- src/spring.luau | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/spring.luau b/src/spring.luau index bd1a990..e9d8fec 100644 --- a/src/spring.luau +++ b/src/spring.luau @@ -201,9 +201,27 @@ local function spring(source: () -> T, period: number?, damping_ratio: number -- set output to goal output.cache = data.source_value - return function() - push_child_to_scope(output) - return output.cache + return function(...) + if select("#", ...) == 0 then -- no args were given + 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