Hello, I would like to implement hovering of objects above ground. The goal is to stabilize the y position of the object above the ground, if the object dropped from a height. In my demo I apply force to the object if a certain minimal distance to the ground is detected. Has anyone has an idea how to calculate the correct amount of force to apply? I think I need to consider the gravity, mass of the object and maybe also the current velocity. Thank you very much. Here is my demo so far:
You could try playing with linearDamping and angularDamping.
https://www.babylonjs-playground.com/#WAFYKC#2
Or maybe look at some examples of how raycast vehicles are implemented. Specifically suspension.
thank you for the hints!
Excellent! I’ve been looking for the correct hover calculation a long time @Raggar for controlling the drones/helicopters/ufo’s in my game
The 3 drones in the image now each hover at a different altitude from the ground. (Before this fix they just fell down from the sky and scattered into a thousand pieces on the ground…) Thanks!
Q
Sounds awesome! Do you mind to share some relevant code snippets? Thank you very much @QuintusHegie
Hi @mklan sure.
Just see lines 74 until 87 in the playground https://www.babylonjs-playground.com/#WAFYKC#2 listed above by @Raggar . That’s what I copied into my game. Change the fixed value 2 (in those code lines) to the hovering altitude of your choice.
(More advanced option would be to have a raycast down from you hovering object, so that the object hovers at fixed distance above the ground, even when the ground is not flat but has slopes hills mountains etc.)
Q
Oh man I am blind :). Thank you again @Raggar and @QuintusHegie!
@mklan Please mark the reply that is the solution to your question. As people don’t have to click on the question thinking it is still not answered.