Hovering objects

I’m working on a vehicle in my game that acts as a hovering craft of some sort. Not just off the ground but at varying heights. The following link is what I’m using to help me so far.


So how do I manage to keep an object hovering in mid air but also leave it open to being moved?

Theres a test for that in the jme3tests package, look at TestHoveringTank and HoverControl. I simply used a vehicle raycaster but you can of course cast the rays yourself.

I see the actual code. My problem is I want to do this at multiple heights, not a few feet off the ground.

Yeah, then you need to create a fly-by-wire system that simply puts the right forces onto the object so it doesnt fall. Let me tell you that is not easy.

So I have to manually account for all the forces and angles on all 3 axis?

Yeah, sure.

Isnt it easier to use a cinematic and rays and “simulate” the hovering?

I believe it would be faster, easier and provide you with the same result, wouldn’t it?

I’m a bit confused by what you said. A cinematic is just a cutscene. Are you suggesting that I create cutscenes for every possible action the hovering vehicle can make and call them accordingly? That sounds fairly intensive. And where are the rays coming into place here?

I made hovering enemies for a game; you could use the same method. I used normal physics objects with a really high damping, set the gravity to 0, and then had a Vector3f for where the thing was supposed to be. Then I used applyForce() to make the damped weightless object go where it was supposed to. Then you only have to worry about rotation - I made the model lookAt() its target, but you would probably want to have turning based on controls or something. In that case, you could apply forces off center or apply torque, if that is possible.

I’ll attempt this and see where it goes. However, if I set the gravity to 0, then how would I account for other objects that do not hover and are affected normally? Two sets of physics environments?

Oh…sorry… I used the wrong term. Was a bit in a hurry back then…

I meant Objects with no mass… so they are not affected by the gravity and stuff. My fault. :smiley:

You dont have to set the gravity zero. Just set the mass of the object 0 and it will hang where you place it. :wink:

You can set the gravity to 0 on the “weightless” rigidbody and to normal gravity on the rest.

Two PhysicsSpaces would not enable the rigidbodys in each PhysicsSpace to ineract with each other.

Ok. So what command where am I using to set the gravity on rigidbodycontrol to 0? I looked in PhysicsSpace and RigidBodyControl API and found nothing that would clearly do that.

setGravity() in both physicsSpace and rigidBody is not clear enough?

I read through the wrong section. My mistake.