I aksed my friends how to make this smooth moving effect on your viewmodel when you move your camera around and i always wanted this effect because it looks so freaking smooth my friends told me i should use this module script:


local spring = {}
local cf = CFrame.new
local ca = CFrame.Angles
local v3 = Vector3.new
local rad = math.rad
local min = math.min
local max = math.max
local sin = math.sin
local cos = math.cos
local floor = math.floor
local random = math.random
function spring.new(start, d, s)
	start = start or 0
	local t0 = tick()
	local p0 = start
	local v0 = 0 * start
	local t = start
	local d = d or 1
	local s = s or 1
	local function update(tick)
		local x = tick - t0
		local c0 = p0 - t
		if s == 0 then
			return p0, 0
		elseif d < 1 then
			local c = (1 - d * d) ^ 0.5
			local c1 = (v0 / s + d * c0) / c
			local co = cos(c * s * x)
			local si = sin(c * s * x)
			local e = 2.718 ^ (d * s * x)
			return t + (c0 * co + c1 * si) / e, s * ((c * c1 - d * c0) * co - (c * c0 + d * c1) * si) / e
		else
			local c1 = v0 / s + c0
			local e = 2.718 ^ (s * x)
			return t + (c0 + c1 * s * x) / e, s * (c1 - c0 - c1 * s * x) / e
		end
	end
	return setmetatable({
		accelerate = function(_, a)
			local time = tick()
			local p, v = update(time)
			p0 = p
			v0 = v + a
			t0 = time
		end
	}, {
		__newindex = function(_, index, value)
			local time = tick()
			if index == "p" then
				local p, v = update(time)
				p0, v0 = value, v
			elseif index == "v" then
				local p, v = update(time)
				p0, v0 = p, value
			elseif index == "a" then
				local p, v = update(time)
				p0, v0 = p, v + value
			elseif index == "t" then
				p0, v0 = update(time)
				t = value
			elseif index == "d" then
				p0, v0 = update(time)
				d = value < 0 and 0 or value < 1 and value or 1
			elseif index == "s" then
				p0, v0 = update(time)
				s = value < 0 and 0 or value
			end
			t0 = time
		end,
		__index = function(_, index)
			if index == "p" then
				local p, v = update(tick())
				return p
			elseif index == "v" then
				local p, v = update(tick())
				return v
			elseif index == "a" then
				local x = tick() - t0
				local c0 = p0 - t
				if s == 0 then
					return 0
				elseif d < 1 then
					local c = (1 - d * d) ^ 0.5
					local c1 = (v0 / s + d * c0) / c
					return s * s * ((d * d * c0 - 2 * c * d * c1 - c * c * c0) * cos(c * s * x) + (d * d * c1 + 2 * c * d * c0 - c * c * c1) * sin(c * s * x)) / 2.718 ^ (d * s * x)
				else
					local c1 = v0 / s + c0
					return s * s * (c0 - 2 * c1 + c1 * s * x) / 2.718 ^ (s * x)
				end
			elseif index == "t" then
				return t
			elseif index == "d" then
				return d
			elseif index == "s" then
				return s
			elseif index == "m" then
				local p, v = update(tick())
				return p.magnitude
			end
		end
	})
end
return spring

and i have no idea how to use it could please someone help me out with this thank you :-)

1 comment

0

Why do you have variables for every function lol