Implementing floating objects

arttu
Posts: 2
Joined: Fri Aug 28, 2009 7:32 am

Implementing floating objects

Post by arttu »

Hi everybody!
This is my first post on this forum so go easy on me :wink:

I have a static world that consists of btBvhTriangleMeshShapes and btStaticPlaneShapes. Currently everything works fine, but there's no "floating": what I'd like to implement is a moving object that floats above one of the static objects, much like magnets repel each other or like (well, not much like) a helicopter gets more lift when it's near to the ground.

Is it sensible to implement the above by:
- creating an object that represents the surface that causes the "float". This object would not be rendered visually but it would only be used for physics calculations
- multiple rays would be cast from the floating object's underside and then with the magic of pseudo code I would:

Code: Select all

for all rays {
   if(ray hits a surface which causes floating){
     length=length from ray's starting position to collision point
     force=(MAX_FLOAT_FORCE-length)*ADJUSTMENT; // so force is stronger when closer to the surface
     if(force>0) { // object is close enough for the force to "reach it"
         apply force to moving object (to the place where the ray started) to the direction of the surface's normal
     }
  }
}
The more rays I'd have the more accurate the floating calculations would be, but I guess for my purposes only couple of rays would be enough.

....or is there a completely different approach that would be better suited for my needs? I haven't looked at ray casting at all yet - I took a quick look at Raytracer.cpp but haven't "digested" it yet - so is what I suggest above even feasible with bullet physics? All kinds of suggestions and comments are more than welcome!
garvek
Posts: 6
Joined: Tue Aug 25, 2009 10:26 pm

Re: Implementing floating objects

Post by garvek »

Hello,

Instead of using simple raycast you may use shaped ray cast, this will avoid multiple ray casts.

Another way also would be to define a collision filter, and allow only your very object to collide with the shape you provide as a floating area.

If you want the float effect also the shape has to be flat at the top, else your object may fall from it, which wouldn't be quite the effect desired.