Skip to content

Commit

Permalink
SPHI-21 Added spring impulsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaGobble committed Aug 1, 2024
1 parent d203605 commit 64295df
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Components/Animation/Spring.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ function Spring:__call(Value : any, Speed : number, Dampening : number) : Spring
return PackType(PackedValues, ValueType)
elseif Index == "Changed" then
return ChangedSignal
elseif Index == "Impulse" then
return function(self, AmountValue : any)
local UnpackedAmount = UnpackType(AmountValue, ValueType)

for Index, Spring in ipairs(UnpackedSprings) do
local Amount = UnpackedAmount[Index]
local Position, Velocity = GetPositionDerivative(Speed, Dampening, Spring.Position0, Spring.Coordinate1, Spring.Coordinate2, Spring.Tick0)

Spring.Tick0, Spring.Coordinate1 = os.clock(), Position

if (Dampening >= 1) then
Spring.Coordinate2 = Spring.Coordinate1 + (Velocity + Amount) / Speed
else
local High = math.sqrt(1 - Dampening * Dampening)

Spring.Coordinate2 = Dampening / High * Spring.Coordinate1 + (Velocity + Amount) / (Speed * High)
end
end
end
end

return nil
Expand Down

0 comments on commit 64295df

Please sign in to comment.