Physics Based Spring Module V2.0

This is great! Is there any way I can use this to create a camera system similar to the one seen in Doors? I’m currently working on a game similar to Doors and I really want to replicate their camera system.

Did I understand any of the math equations he was talking about?
No.
Will I use the module anyway knowing I probably won’t know how to use it?

ABSOLUTELY!

:heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart: :heart:
best module ever!!!

1 Like

Update 11/9/2023 (SpringModule V2.0)


  • Reworked damping: Instead of dampingForce = dampingConstant, it now works as dampingForce = dampingConstant*mass. Damping force should now change with mass.

  • New constructor: Added new Spring.fromFrequency() constructor. This takes in a frequency instead of a spring constant, and calculates the spring constant of the spring to match the given frequency. Frequency is the time it takes for the spring to complete a full oscillation.

  • SpringObject:SetFrequency: Added SpringObject:SetFrequency() function. This function takes in a frequency and sets the spring constant of the SpringObject to match the given frequency.

  • SpringObject:SnapToCriticalDamping: Added SpringObject:SnapToCriticalDamping() function. Calling this function will snap the spring to critical damping by changing the damping. Critical damping is the point where the Spring turns from exponential motion to oscillating motion.

  • SpringObject:SetOffset: Added SpringObject:SetOffset function. Calling this function will set the offset of the SpringObject to the given offset. If zeroVelocity argument is true, this function sets the velocity of the SpringObject to 0.

  • SpringObject:SetVelocity: Added SpringObject:SetVelocity function. Calling this function sets the velocity of the SpringObject to the given velocity.


For new documentation, please refer to the github documentation!


Get the new version of the module here!


Don’t hesitate to ask questions about this update, I’ll try my best to answer all questions! :V

5 Likes

Hi,
Do you have an example .rbxl of a working spring?

Thanks

Man, im looking at the desmos graph, AND I LOVE WHAT I SEE!!
thank you so much for working on this!
you’re the best

Can this spring module be used for UI?

Yes, a Spring object calculates a single number. Because of this, the Spring is by design 1D. To make it 2D, just create and use two springs and change the properties of each spring according to their respective X/Y directions.

1 Like

Should this still be used in 2024?

heck yeah

char limit

what? oh now i know :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients: :coefficients:
anyways i might use this module!
edit: oh and also if you look in the player module code you will find a spring module but i dont think its this one or is it?

I would wait until 2025, then see if it should be used then if so then yes

1 Like

yeah, definitely.

I’m absolutely in love with this module, and I use it almost everywhere where it is needed to be use.
Whenever I need a nice elastic simulation of harmonic motion, shake, smooth interpolation, or anything related to that - I use this awesome module.

utterly lovely, my recoils look almost as good as Weaponry!

So this doesn’t support Vector3??? Do I just make 3 springs independently?

1 Like

Yes, just make 3 springs: this is a common approach for physics modelling.

2 Likes

How can I fix the problem with different fps?
The thing is that the intensity of the spring affects directly on the fps, I tried multiplying offset by dt60, but it also did not help, after the setvelocity(numberdt*60), it also did not help me, the question, what am I doing wrong? :sweat_smile:

function CameraController:update(dt)
	local offsetX = math.rad(self.SpringX.Offset)
	local offsetY = math.rad(self.SpringY.Offset)
	local offsetZ = math.rad(self.SpringZ.Offset)
	--offsetX*dt*60 - like example
	local newCamCF = CFrame.Angles(offsetX, offsetY, offsetZ)
	self.Camera.CFrame *= newCamCF:ToObjectSpace(oldCamCF)
	oldCamCF = newCamCF
	
end

function CameraController:jump()
	--self.SpringX:AddVelocity(25*self.dt*60)
	self.SpringX:AddVelocity(25)
	self.SpringY:AddVelocity(0)
	self.SpringZ:AddVelocity(150)
end
1 Like

It depends on the settings you used for your spring. The spring module itself uses its own timer to figure out the offset of the spring. Multiplying by dt will not do anything, as the module should already be calculating its offset depending on its initial parameters. Make sure your initial parameters are correct. Try using the Desmos graph I made for changing the parameters!

i ran into the same issue with the module not being consistent across different FPS, im not using delta time at all like u said. 60 fps gets about a 4th of the effect that 240 gets. and i cant imagine changing the initial parameters would change this

I’ve answered this question a few times, check out this post: