SetCenteralForce() for hovercraft-like effect?

Hi everyone,

I am new to Jme3 and I thought I would implement a box that acted similary to a hovercraft. So, every update, I do: setCenteralForce(new Vector3f(0, 100, 0) onto my “vehicle” controller. It seems to be that at first the box jumps up into the air, then gravity(it is set worldwide to -9.8f) takes over and it crashes down. Then, it sort of “hops” up in the air. What I was hoping for is that it would jump up, then go down, then jump up again, ect… I tried to use the physics tick listener rather than the update method, but the physics preTick “space” doesn’t have methods such as applyForce ect… I am not sure why. Also, for some reason the box doesn’t seem to care abiyt where I position it. I set the setLocalTranslation of it to -1000 (when the terrain is at -100) and it was still at the same location. Apologies for the messy code, I tried many things and commented them out. What methods / tequnchies should I be using for a floating-like effect?

Many thanks!

You set the physicsLocation on the physics control, not the spatial when you use physics controls because the physics engine controls it’s presence.

If it were me I’d apply an impulse multiplied by time (tpf) which will make it nice and smooth.

Ah, I see. I’m doing a test run right now and it seems to be that preTick method is not being called, I put a println() in there.

I will use physicsLocation to set the location now instead of the spatial.

I have little idea as to why prePhysicsTick is not call, here is my code:

The other method(physicsTick) is not call either

EDIT: For anyone else wondering, you need to add the tick listner with appState.getPhysicsSpace().addTickListener(this);

Is there a way to set it to be a certain distance above the current ground? I did setImpluse(new Vector3f(0, 50, 0), new Vector3f(loc.x, loc.y - 2, loc.z);

where loc is getPhysicsLocation since the box is 1 in both direction for the y. However, the box keeps toppling over and it just isnt smooth…

So i thought I could do that then add a random.nextDouble() to make it look like hovering

The location of the impulse is relative to the objects center. It’s a local translation, I guess, for want of a better description.

If you are using the Box geometry, a 1,1,1 would be 2 units in length, so your impulse location could either be just 0,0,0 or 0,-1,0

Okay… so now I apply the impulse at spatial.getWorldTranslation() but it still jumps around a ton, I have it only impulse when deltaTime >= 0.5

I edited my reply. You ninja’d me :stuck_out_tongue:

1 Like

Ah. I set it to (0, 0, 0) or worldLocation(it make no difference) and this happens:

It’s sort of like"dancing" as if the impulse isn’t being spread evenly

Do I need to set the impulse on each of the four corners?

Actually in my mind it seems reasonable it would do that if the impulse is too great.

You could try balance it using 2 (front back) or 4 (each corner).

It would probably need some interesting mathematical formula to determine the unit impulse required for each corner to balance the thing and keep it level.

You could start maybe by using the rotation of the object. If your object is rotated on the x axis at quarter pi or more, zero impulse is applied on the left side, and anything below quarter pi is between 0 and 1, which you can use as a mult for the impulse force.

I hope that makes sense. Welcome to the wonderful world of maths.

Oh wow… there’s no quick and easy way to hover then, I see… I was think for now I’d just do it when its completely level and apply an impulse of 2 on each corner. should that completely stablize it? I find it weird that applying an impulse to the center leavings one point on the ground… is that randomly determined?

Not really. But applying an “up” impulse is relative to the rotation of the object. Just like a helicopter, if the thing is upside down, up force becomes down force, and tilting slightly forward applies a rotated force to move it forward and up, and because the up force of a rotated vehicle is also now sideward force, more force is required to keep it up.

Physics in a computer is only a simulation of step-wise math. Normally forces balance out such that an object sitting on the ground doesn’t rock back and forth (though it will if accuracy is set low enough).

I think when you start lifting it off the ground, you capture some of that instability and things go out of balance.

…that being said, I’ve applied upward impulses to the center of things and they don’t spin. So it may be related to other things.

Ah… I see… apply a impulse to the 4 corners and the center still results in some “dancing-ness” although less… I’m not sure if anyone else has every created a hovercraft (I found one ancient thread on it from '08)

Probably the easiest way to create a hover craft is with a car with invisible wheels and no friction.

Hmm… How would I be able to get the radnom up/down motion then?

that being said, I’ve applied upward impulses to the center of things and they don’t spin. So
it may be related to other things.

Hmm… if possible would you be able to take a look at my code? It would be appreaciated as it seems that this isn’t suppose to happen.

Animate it?

Welcome to computer games where 70% is smoke and 80% is mirrors. :slight_smile:

vehicleControler.applyImpulse(new Vector3f(0, 2, 0), new Vector3f(2, 0, 2));

The first vector should be multiplied by tpf to apply a constant force.

Your deltaTime is going to be different every time and cause seemingly randomly timed impulses.

How did I never think of that… spent days on the computer trying to figure it out! Thanks a ton!

Oh yeah… I forgot that, I thought it was only for different machines but now I realize its also for varying FPS

yes, using tpf makes it not rotate but its not as smooth as I would want to be… animation is what I think I will do… I’m not exactly sure how to use blender so I would have to use motion-events then, but not sure what ocordintaes to use for that, so maybe I’d use blender animations then

EDIT: Nevermind, the Jme3 beginner tuts have good info on animation :stuck_out_tongue: