Hello, i am following this video: the video , and i am trying to implement a spring based character hover.

this is what i have so far:

the problem that i am facing is that the character won’t stop jumping

here’s the ModuleScript:

function Controller:Hover()
local delta = run.Heartbeat:Wait()
local raycastDirection = -self.playerCharacter.playerCapusel.CFrame.UpVector * (self.maxSpringLength + self.rideHeigth)
local rayParmas = RaycastParams.new()
rayParmas.FilterDescendantsInstances = {self.playerCharacter}
rayParmas.FilterType = Enum.RaycastFilterType.Blacklist
local rayCast = workspace:Raycast(self.playerCharacter.playerCapusel.Position, raycastDirection, rayParmas)
local disSpringLength = 2
if rayCast then
local rayCastDistance = (self.playerCharacter.playerCapusel.Position - rayCast.Position).Magnitude
local springLength = math.clamp(rayCastDistance - self.rideHeigth, 0, self.maxSpringLength)
local StiffnessForce = self.Stiffness * (self.maxSpringLength + self.rideHeigth)
local DamperForce = self.Damper * ((disSpringLength - self.rideHeigth)/delta)
local springVector = self.playerCharacter.playerCapusel.CFrame.UpVector * (StiffnessForce+DamperForce)
disSpringLength = springLength
self.playerCharacter.playerCapusel:ApplyImpulse(springVector, rayCast.Position)
else
disSpringLength = self.maxSpringLength
end
end

and here’s the activation script:

local characterController = require(rep.OPP_SYSTEMS.characterController).init(2, 3, 80, 3, playerCapusel)
local function update()
characterController:Hover()
end
run.Heartbeat:Connect(update)

I’ve done this before in javascript. The object never stopped bouncing.

You have to stop it manually. When it’s bouncing under a specific value, just stop bouncing.
Because if you’re dividing it’s bounce by a number, it’ll never approach zero. It’ll just get smaller.

What I would do is, after casting the ray, multiply the spring by some constant less than 1 and greater than zero, and then every time check if the spring value is under some constant. if so, set the spring to zero, and break the loop so that it will stop bouncing.

Once the height goes under a certain threshold, you stop bouncing.

You can apply like this:

local t = 0 -- x
local stopt = math.pi+math.pi*5 -- where you stop, 5 is directly proportional to the amount of times it will bounce. sorry for the edits :/
local i = (1/stopt*10)*math.pi -- the bigger *10* is, the more smooth your bounce will be.
local o = part.Position.Y
function f(x)
return math.abs(math.sin(x-math.pi)) * math.abs(7/x-math.pi)
end
while t < stopt do
part.Position += Vector3.new(0, f(t)-part.Position.Y, 0)
wait(i)
t += i
end
part.Position.Y = o

bruh i am losing my mind right now, there has to be an easier way to do what i am doing.
if anyone knows please reply. this project is going to drive me insane

The method I’m talking about isn’t really that hard lol. If you saw the function I gave you, it obviously bounces. I was just incorporating a little of my math knowledge to help you in the long run.

Basically the function just uses t and the function f(x) to get the desired y level of your point, and you can see it… obviously bounces! If we plugin any value to the f(x) formula, the value will go up and down accordingly. So all we have to do is make a while loop that iterates every value and then add/subtract that value off of the y-position of the part.