Trying to achieve a spring based character hover

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 =
	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)
		disSpringLength = self.maxSpringLength

and here’s the activation script:

local characterController = require(rep.OPP_SYSTEMS.characterController).init(2, 3, 80, 3, playerCapusel)

local function update()


how can i possible solve this issue?

1 Like

Quick bump to make sure people see this, uhh another dead post thanks devforum :+1:

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.

oh finally human contact, i will try that and see if it works

1 Like

I think the reason why it goes back up has to do with the velocity. When the ball starts bouncing faster, the velocity increase so it gets stronger.

so your saying i should cap the velocity?

No, I’m saying that you should stop it after the character bounces under a specific height. Because after that it will start bouncing faster.

Do you get it?

I don’t understand how your code works, If you could explain?

ok i will explain in the best way possible,

i cast a ray from the character to the ground, then i apply a damping spring so the player character will remain at its ride height

How do you apply that “damping spring”?

i have no idea, thats what i am trying to figure out

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.

1 Like

Also, check this out:

Try using this formula to determine the spring.

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)

while t < stopt do
part.Position +=, f(t)-part.Position.Y, 0) 
t += i
part.Position.Y = o
1 Like

The approach I always found to work is, first of all, disable gravity(a body mover with the objects mass * gravity) and then apply spring math.

1 Like

you may want to stop it on a multiple of pi or tau though. It might stop in the air :open_mouth:

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

i found this twitter video: that kinda replicates what i am going for.

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.