Issues with detecting collisions between specific bodies?

Post Reply
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Issues with detecting collisions between specific bodies?

Post by jimjamjack »

I'm attempting to delete an object (remove its rigidBody and stop rendering it) when it is hit by an other body. In particular, in my scene there are wall/floor rigidBodies, target rigidBodies and bullet rigidBodies. When a bullet hits a target, I want the target to be deleted.

I'm using the "iterate through the manifold" technique.

Can anyone help me with this problem? Thanks.
Last edited by jimjamjack on Mon May 01, 2017 9:54 pm, edited 1 time in total.
S1L3nCe
Posts: 50
Joined: Thu Mar 24, 2016 10:22 am
Location: France

Re: Issues with detecting collisions between specific bodies

Post by S1L3nCe »

Hi,

There is a similar thread treated that: http://bulletphysics.org/Bullet/phpBB3/ ... hp?t=11507
Can you try what's in it and give us some feedback if your problem persists?
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Issues with detecting collisions between specific bodies

Post by jimjamjack »

Unfortunately the bullet wiki code sections seem to be down (at least for me), so I can't check the pages recommended in that thread.
As for the solutions, I don't think they solve my issue. I thought that "const btCollisionObject *objA = contactManifold->getBody0();" would get the body that has had a collision, but when I get its userIndex, it's higher than the indexes used for my bodies.

E.g. my bodies are indexed by the order they're created (so my targets are indexed from 0 to targetNum -1, then my walls, floor and ceiling are indexed after that and so on with the bullets).
But objA.getUserIndex() results in an index higher than all of my bodies (say I have a total of 8 rigidBodies in my scene, it will give me 9). This means that I can't check if the object that had a collision is a target (i.e. its userIndex is < targetNum).

Cheers for any ideas.
S1L3nCe
Posts: 50
Joined: Thu Mar 24, 2016 10:22 am
Location: France

Re: Issues with detecting collisions between specific bodies

Post by S1L3nCe »

What kind of value give you the getUserIndex ?

After your bullet bodies create process, try to loop at all bodies includes in the bullet worlds. Then display their user index and be sure that they are correct.

Anyway you should try to use a more convenient way to detect what kind of body is colliding (quoting benelot):
Your problem has to be solved in an inverse manner. When you create your rigidbodies, you have to set the userpointer to something like the object of your class or similar to access it on collision.
...
Code:

Code: Select all

//Assume world->stepSimulation or world->performDiscreteCollisionDetection has been called

btPersistentManifold* contactManifold =  world->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

//... here you can check for obA´s and obB´s user pointer again to see if the collision is alien and bullet and in that case initiate deletion.
jimjamjack
Posts: 39
Joined: Tue Jan 31, 2017 8:07 pm

Re: Issues with detecting collisions between specific bodies

Post by jimjamjack »

All of the userIndexes are correct, yes (I know using a number n to index them isn't the best idea). objA->getUserIndex() returns the last index, and objA->getUserIndex() returns the last index+1 (So e.g., with 8 targets and 6 walls, objA->getUserIndex() gives 13 and objB->getUserIndex() gives 14). What's strange to me is that using the raycasting method to get a body's index works just fine (RayCallback.m_collisionObject->getUserIndex() gets the correct index).

Is there another way to test for collisions maybe? Or any other possible fixes?
Post Reply