Collision masks

Post Reply
sjcomp
Posts: 2
Joined: Wed Apr 28, 2010 6:19 am

Collision masks

Post by sjcomp » Thu Apr 29, 2010 12:21 am

Hello,

I have ships and bullets. Ships collide with bullets and with each other. I do not want bullets to collide with other bullets. So I have three collision masks:

Code: Select all

enum ECollisionTypes
{
	NO_COLLISION		= 0,
	SHIP_COLLISION		= 1 << 1,
	BULLET_COLLISION	= 1 << 2,
};
I create my ships and bullets with the following flags.

Code: Select all

// Create bullet, does not produce any collision?
collisionWorld->addCollisionObject(pBullet, BULLET_COLLISION, NO_COLLISION);
// Create ship.
collisionWorld->addCollisionObject(pShip, SHIP_COLLISION, SHIP_COLLISION | BULLET_COLLISION);
Unfortunately, I register no collisions between bullets and ships. If I create bullets with a SHIP_COLLISION flag, then it works:

Code: Select all

// Create bullet, creates collisions.
collisionWorld->addCollisionObject(pBullet, BULLET_COLLISION, SHIP_COLLISION);
From wiki I thought that I can should use NO_COLLISION. Am I missing something here?

Thanks.

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Collision masks

Post by Flix » Thu Apr 29, 2010 12:15 pm

sjcomp wrote:From wiki I thought that I can should use NO_COLLISION
Well, if I've understood correctly you've solved the problem...

From what I know:
a) The collision group just determines the GROUP of the object.
b) The collision flag determines the GROUPS with which the object can collide.

However since if a can collide with b, b must be able to collide with a too, you must set for your "bullets" the collision flag "ships" (or simply "everything except bullets") too.
Probably if one sets all the collision flags more generally with "everything except XXX", these problems hardly happen.

Hope it helps.

Post Reply