How to make part float with BodyForce x studs off the ground?

I’m trying to make a more complicated character movement system. I decided to rewrite the base to be custom, and not the default roblox movement.

So far i made the part resist gravity by multiplying Mass with workspace.Gravity. But i only want to make it resist gravity at, let’s say 4 studs off the ground. If higher than 4 studs, less force is applied. If lower, more is applied.


image
X is the force needed.
10 is just an example of the force needed to overcome gravity.
4 is an example floating distance in studs.
Y is the actual distance from the ground.
At the 4 stud mark (y=4), the force just becomes the force required to overcome gravity, since that’s the floating distance.

But as of now, it just oscillates:

So how can i make it stop oscillating?
I’ve heard of PIDs, but i could never figure out how to implement.
Any help is appreciated.

EDIT: Forgot this. It’s late and i’m dumb.
Float.rbxl (30.5 KB)

3 Likes

How about a BodyPosition?
You could make just the Y variable have any force on it.

That would require ray casting to get it correct, because it wouldn’t float on top of all surfaces

I feel like I should know, but what are PIDs? And also - is there a reason for not using a BodyPosition object (since that does all of these calculations under the hood)? I feel that would make this significantly easier.

1 Like

You can use body velocity with the following properties:


to reduce to oscillation (by alot).

PID is just a function that reduces the oscillating nature of theese systems. Have a read. But i just learned about PIDs a couple of days ago myself.

That would be the rigidity of them. No matter how i tweaked them, they seamed too rigid. Might be a “me problem”, so i haven’t given up on them just yet.
Also, at some mass the BodyMovers ignore friction. So if i stand on a moving platform, it just slips out under me.

I see you there.

Also it’s just more dynamic.

BodyVelocity seems like a nice middle ground, but i still have to make it float. Or i can slide it, but friction would become a factor.
I will update this comment!

1 Like

You can change the friction values with CustomPhysicalProperties. This may make a difference with parts of certain masses having friction ignored with BodyMovers.

Good point, but i knew this already.
Also, if there is less friction, a human would accelerate and stop slower. But the previous version used BodyVelocity while sliding the character, and less friction made the character more responsive. There were 2 versions made by me before this rewrite.

Hence: floating brick.

@Lightlimn @Pure_Bacn
I think i can work with this from now on. I still need to figure out how to make the part float around a certain height, but i can just chuk that into a PID and fine tune it.

Work awaits. Thank you for your time.

1 Like