I’m currently experimenting with springs and I’ve written this code:
local spring = {}
spring.__index = spring
function spring.new(Object, TargetPos, Tension, Dampening)
local self = setmetatable({}, spring)
self.Object = Object
self.TargetPos = Object.Position.Y + TargetPos
self.Tension = Tension
self.Dampening = Dampening
self.Speed = 0
return self
end
function spring:update(dt)
local displacement = self.TargetPos - self.Object.Position.Y
self.Speed += (self.Tension * displacement) - (self.Dampening * self.Speed)
self.Object.Position += Vector3.new(0,self.Speed,0);
end
return spring
The spring:update() method should run every .RenderStepped on the client. Everything works well on 60 fps but I’m not sure how this will run on slower or faster frame rates. I don’t have any way of testing this since roblox doesn’t have a built in frame rate limiter into studio. I’m still trying to understand deltatime and how I can make my code work on all frame rates, if somebody could explain to me exactly how deltatime works that would be appreciated.