Hovercraft - need hint please

autofreax
Posts: 4
Joined: Fri Apr 08, 2011 8:35 pm

Hovercraft - need hint please

Post by autofreax »

Hello Guys - i am playing around with simulating hovercrafts.

Until now I have simulated the "hovering" by low friction - which works well for developing the steering - but is not what i want.

I am working with my hovercraft (collision box) and 9.81 gravity. As far as i have worked out it should be possible to just apply an counter-force to the gravity.

To do it, I compute the 4 corner-points of my hovercraft, calculate the distance to the floor (which is only a simple plane at the moment) and generate a counterforce for each corner.

i am doing this in tickcallback (prestep)

Code: Select all

// corner = (0,-1,0) and so on for each corner
btVector3 world_corner;
world_corner = trans(corner); // get corner in world space
float altitude = wcorner.y(); // just get the height of the corner in worldspace
if( altitude < 1.0f )  // treshold in which counter-force is applied
{
  btVector3 force(0,-(9.81f*player.weigth),0); // make "anti-gravity", weigth = ~290kg, so max anti-grav = 2900N .. ?
  float diff = (altitude-1.0f); // compute relative
  force *= diff;
  btVector3 trg = corner;
  trg.rotate(tt.getAxis(),tt.getAngle()); // transform to object space, tt = getRotation from worldtransform
  body->applyImpulse(force*timestep,trg); // apply to rigid body corner
}
Looks easy .. but that's not working - body gets choppy and starts hopping around after collision - initial and with slow moving everything works fine

I think it is because of the applied torque which brings down the opposite edge again and so on.

Is my approach generally wrong or do i need any special value for AngularFactor ..? As far as i can imagine the torques on each corner should eliminate themselfs and only the strongest should survive.

Any help would be highly apprecated

...also how can i prevent the body from ever touching the ground .. infinite anti-grav .. do i need to handle gravity myself for that?
autofreax
Posts: 4
Joined: Fri Apr 08, 2011 8:35 pm

Re: Hovercraft - need hint please

Post by autofreax »

can anyone tell me the difference between

Code: Select all

btTransform trans = getWorldTransform(trans);
btVector3 vec_result = vec_point*trans->getBasis()
and

Code: Select all

btQuaternion rot = trans->getBasis();
btVector3 vec_result = vec_point.rotate(rot.axis,rot.angfle):
The first approach (with getBasis) - rotates in the other direction .. ? inverted axis? why?

Indeed i got it to hover - but it feels more like a hovering saucer than a hovercraft - so i will stick to my "low-friction" approach - it does feel much more than a hovercraft this way ;-)
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Hovercraft - need hint please

Post by Flix »

I've never used btVector3::rotate(...) so I'm going to answer to this question only:
autofreax wrote: btTransform trans = getWorldTransform(trans);
btVector3 vec_result = vec_point*trans->getBasis();// rotates in the other direction .. ? inverted axis? why?
I think it happens because Bullet allows btMatrix3x3 vs btVector3 multiplication in both ways, like this (hope it's correct... :? ):

Code: Select all

SIMD_FORCE_INLINE static btVector3 LocalToGlobal(const btMatrix3x3& in,const btVector3& v)	{
	return in*v;
}
SIMD_FORCE_INLINE static btVector3 GlobalToLocal(const btMatrix3x3& in,const btVector3& v)	{
	return v*in;
}
So maybe you may try swapping the factors...
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Hovercraft - need hint please

Post by Erwin Coumans »

Indeed, use

Code: Select all

btVector3 vec_result = trans->getBasis() * vec_point; 
instead.
autofreax
Posts: 4
Joined: Fri Apr 08, 2011 8:35 pm

Re: Hovercraft - need hint please

Post by autofreax »

sure, now i understand - never thought about displacing the vars.. :oops:

thank you for clearing me up!

i cannot test it at the moment because of doing another approach. but at the end the hovering works pretty good - but more like an ufo - low friction is better for doing hovercrafts. Nevertheless - i liked it and will make another game with the "ufos" later ;-)