How to make a camera following player using springs module?

I’m trying to make a smooth camera motion so when it follows the play, the camera would make a smooth motion. By archiving this plan is to applied a spring motion to it, which I’m struggling to make it work. This would be probably a little hard at least for me since I’m not a pro scripter myself. If anyone know how to make the smooth camera works with spring, it would be super nice and helpful to help me out archiving this plan to work

1 Like

Why not change the camera position every .25 secs or so and take the current cameras position and tween it to where it should be in a circular motion.

Haven’t tried it but will it be more efficient to use tween tho? I mean I never tried it before. It would be a little complicated. So I want to apply spring module to it so it would make that spring motion without using tween stuff

I personally dont use tween service but instead I use something like this:

function Lerp(a,b,c)
    return (a-b) * c
end

a - starting point
b - end point
c - decimal of completion (0-1) 1 being completed

From there all you would need to do is get all the points on a curve around the character. Or you could use a stick and tween the rotation of the stick and set the camera to the end of the stick

What do you mean by the stick? Like defines camera orientation?

so if you were to rotate a stick it would create a circle, its a neat way of controlling cameras

Yeah but I don’t think that’s not what I want to archive tho. What I want to archive is to make a smooth camera like a car game called Forza 5 I believe

When you say spring motion, you mean sort of like the elastic EasingStyle? To integrate this into a camera system, you’d want to do what @minimic2002 is saying, and you’d apply these sorts of things using lerp. Since it’s not typical that you could access TweenService alongside camera lerping, you could create your own functions and keep it in a module like this, then reference them:

local function InElastic(t:n, b:n, c:n, d:n, a:n, p:n):n
	if t == 0 then return b end
	t /= d
	if t == 1 then return b + c end
	if not p then p = d * 0.3 end
	local s:n
	if not a or a < abs(c) then
		a = c
		s = p / 4
	else
		s = p / (2 * pi) * asin(c/a)
	end
	t = t - 1
	return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
end

-- if you're looking for inout, outin, you can just re-adjust the position of said variables and adjust it to that point...

Then, of course, you could use lerp to get a specific variable each time you call to this function to sort of create a ‘spring’ effect on the camera, that of which would look like this when applying it:

--wrapped in a renderstep loop, I won't help out 100% as I don't want to spoonfeed code entirely, hopefully, this can be of some help though, and can give you some insight. :)
local cf = getCF(Points, EasingStyle, Time)) -- Whatever you really want here, you can customize this function to how you want it to be.
Camera.CoordinateFrame = cf;

Hmm I see. This is a pretty short code. Thank you for your help but how do I apply it to the camera or an object in general?

I edited my post, hopefully that can help you out some more. :grinning_face_with_smiling_eyes:

Alright thank you for your time here. Have a good one. I appreciated your effort!

Sure. I hope you figure it out!

Happy coding.

I have a question. How do I add a damping value and speed value to it?

In the values being taken in. The function I sent you has all those sorts of values, if you sort of tweak around with it, you’ll find it to your liking. d in the equation stands for dampening I believe, t stands for the length (which will auto adjust and change how fast it goes overall based on it.)

So basically t is based on speed of the spring?

t is the overall amount of time taken to take from point a to point b. So in a way, yes.

Ah I see. Alright that’s very helpful. Thank you so much mate!

Of course, good luck!

Have an amazing day!

1 Like