This is a module that helps you create chained springs, and even individual ones.
Some showcases with the springs:
https://gyazo.com/38e779185ac351e7416077fd43ec2cf1
https://gyazo.com/f7f20d9726f2cd8e8935dd2775e47a7c
Test FIle
SpringTest (2).rbxl (24.9 KB)
notes:
spring.create(n,damp,t,spread,pos,target)
n is the number of desired springs objects
when passing n>1 then the wrapper would return a ChainedSpringObject.
It’s ok to not define damp,t,spread,pos and target, yet it would error if n is not defined.
the methods of the spring obj when n>1 is not the same when n==1
as example when n==1 there is no
ChainedSprings:GetObjects()
Methods
spring.create(n,damp,t,spread,pos,target)
creates a spring object and there is 2 cases.
n>1
function ChainedSprings:GetObjects()
Returns a table of spring objects, a spring object contains:
{Velocity,LeftDelta,RightDelta,Position,Target,}
function ChainedSprings:Shove(i: number,F : Vector3)
shoves a spring on the index i with a force F
function ChainedSprings:Shove2(i,F)
similar to :Shove1, but this won’t change the target of the chained springs, it would change the velocity.
The first showcase link uses :Shove2.
function ChainedSprings:Update()
has to be called every Heartbeat for the chain to be updated.
n==1
function spring:Shove(v3)
Shoves the spring to some vector3
spring:Update()
has to be called every Heartbeat for the spring object to be updated
** TEST CODE**
local n = 6
local chainobj = spc.create(0.025,0.025,0.1,n)
local parts = {}
for i = 1,n do
parts[i] = {}
parts[i].Part = Instance.new("Part",workspace)
parts[i].Part.Anchored = true
parts[i].Part.CanCollide = false
parts[i].Part.Position = Vector3.new(0,5,i+parts[i].Part.Size.z/2)
parts[i].Pos = Vector3.new(0,5,i+parts[i].Part.Size.z/2)
end
local objs = chainobj:GetObjects()
game:GetService("RunService").Heartbeat:Connect(function()
chainobj:Update()
for i = 1,n do
parts[i].Part.Position = objs[i].Position+parts[i].Pos
end
end)
chainobj:Shove2(1,Vector3.new(0,2,0))--// try Shove1 too