Attaching Rigid Bodies

slavik262E
Posts: 11
Joined: Mon Oct 18, 2010 5:47 pm

Attaching Rigid Bodies

Post by slavik262E »

Hi all. I'm new to Bullet, but am planning to use it for a space flight sim that I'm working on. Please excuse any stupid questions.

The space fighters in my game will orient themselves using a series of thrusters that control the attitude (pitch, roll, yaw) of the ship (akin to how real-life spacecraft work, or for those of you more into sci. fi., the Raptors and Vipers of Battlestar Galactica). Going through tutorials and demo code, my idea would be to represent the ships as rigid bodies and apply torque to change the angular velocity of the ships.

My ships, however, will also have weapons, such as missiles, mounted on hardpoints. I would represent such weapons with their own rigid bodies. This brings up my problem. What would be the best way to attach these weapons to the ship in Bullet? I've looked into constraints, but unless there were some constraints I missed, none hold one rigid body to another, allowing no relative motion between the two. How would I go about doing this? Also, once I attached the weapons to the ship, how could I make the masses and center of gravities of the weapons properly contribute to the net mass and net center of gravity for the entire ship + weapon system?

Thanks in advance for your help.
karwosts
Posts: 6
Joined: Thu Oct 14, 2010 2:00 am

Re: Attaching Rigid Bodies

Post by karwosts »

I'm not really sure you want the missiles to be their own rigid bodies, I think the whole point of the rigid body is that it is it's own moving entity. Even if you could fix it to something it would just cause a ton of extra physics work for the engine for no reason.

For what reason do you feel that you need to do this? Could you consider making your plane's collisionObject a btCompoundShape? This would allow you to combine your plane collisionObject with the weapon's collisionObject in a single rigidbody. Then whenever you switch or detach the weapon you could maybe just switch-out the compoundShape with a new one?

Just an idea.
slavik262E
Posts: 11
Joined: Mon Oct 18, 2010 5:47 pm

Re: Attaching Rigid Bodies

Post by slavik262E »

So you suggest having the ship and the weapons be a single rigid body, then spawning additional rigid bodies when you detach them? My original motivation was to have them be separate collision entities, so a laser/bullet grazing a missile could just disable the missile or something, not do damage to the wing. To avoid excess calculations, I was planning on eliminating collisions between a weapon and its parent ship in the broadphase. Since a rigid body is a subclass of a collision object, how could I have multiple discrete collision objects associated with one rigid body so that I could detect collisions with different parts? Would a compound collision shape do the trick? If so, how would I go about detecting a collision with individual children?
karwosts
Posts: 6
Joined: Thu Oct 14, 2010 2:00 am

Re: Attaching Rigid Bodies

Post by karwosts »

I'm not exactly sure how you will detect which shape in your compound shape receives the collision, but maybe there is some way, you'll probably have to explore the API on your own to try to find out if it is possible.

I know you can get the coordinate where the collision was detected in a callback, but I don't know if there's an easier way to translate that into the specific shape.

If you see this topic I saw from a while back:

http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=2219

Erwin had suggested the same thing (btCompoundShape) for a fixed joint, so I think that might be the right track. I'm still new to this so I was just trying to give an idea, you'll probably have to do some research on your own as this forum is pretty quiet.