Hello! I made a hoverbike a while back and decided to revisit it - I’m currently replacing the BodyPosition it uses to control its altitude (which feels too rigid and causes huge issues if it doesn’t update correctly) with the BodyForce I’m already using for lateral control.
It seems simple enough on paper. Apply a constant upwards force of gravity*total bike mass to counteract gravity; increase this force if the bike’s closer to the ground than the target altitude, decrease it if it’s airborne. Turns out it’s not so simple.
So far, I’ve tried the function from this DevHub article, but with a length offset of 0 and both stiffness and damping set to 10 (I don’t have a frame of reference for what these should be), the formula
-stiffness*length - damping
yields a result of -10. Not what I expect when the bike is at its target altitude, I expect the result to be 0.
What I think I want is a critically damped spring - I don’t want the bike to overshoot its target altitude. The problem with this is I simply don’t understand it. I tried reading this explanation, and only ended up getting frustrated. What’s the angular frequency? I don’t know! Why does it devolve into using imaginary numbers? What do half of these things mean? I don’t even know what the spring constant should be!
I decided to just Google a Lua critically damped spring module. One came up! However, it only seems useful for graphing a spring over time - you give the module a goal, a damping ratio and a frequency, and that’s it. Can’t feed it the current spring length and get a force out of it. Besides, I don’t even know how it derives anything - sure, I gave it a goal, but I never gave it a starting position. ???
So what do I have? I have the current length of the spring (by subtracting the bike’s height off the ground from the target height), and of course I have the free length (the aforementioned target height). I tried things as simple as just multiplying the spring length by the anti-gravity force, but that caused the bike to oscillate violently. I’m incredibly frustrated and have absolutely no idea how to do this, or even how to properly explain it, but I figured even this would be better than not asking for help at all.