About collision groups

Hello,



I am writing an application that needs to detect collision between objects, but I am encountering performances issues. Therefore I decided to use collision groups to reduce the number of collision tests. Basically, I have a scene containing several objects, and one object that is being moved. I want to be notified when this object collides with another one. I tried this:

[java]//a and b are rigid body controls

//a is the object being moved and b is another object of the scene



a.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);

b.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);



a.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);

b.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_NONE);[/java]



After reading the definition of these methods, I expect that if a collision between a and b occurs, it will be reported once, as a collides with the group of b but not the opposite. Instead, no collision is reported to my collision listener.



I then tried this:

[java]a.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);

b.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);



a.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);

b.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);[/java]



This time, collision is reported, but twice. This wouldn’t be a big issue if it only happened with the moved object, but since every object in the scene has these groups, collision are tested between each of them, which is useless.



Am I missing something?

Read the javadoc.

Of course I already did.


Two object will collide when one of the partys has the collisionGroup of the other in its collideWithGroups set.


Excuse me but doesn't it mean that my first solution should work?
@vtheuer said:
Of course I already did.
Excuse me but doesn't it mean that my first solution should work?

Do you use native bullet / android? You don't reduce the number of checks through this btw.

I use native bullet.

About the second point, I thought that those bit masks where used before checking for overlapping between collision shapes, thus preventing costly calculation. Am I wrong?



Thanks for the help btw.

a) Native bullet isn’t done yet, especially the collision part.

b) They are only called when an actual collision happens so its been evaluated before

Maybe it’s a misunderstanding because of my english but isn’t that sentence against what is explained in the wiki docs?.

You can improve performance by resricting the number of tests that collision detection has to perform. If you have a case where you are only interested in collisions between certain objects but not others, you can assign sets of physical obejcts to different collision groups.

(maybe is different now?)

In any case the performance increases because the calculations for the actual collision don’t have to happen. How soon (e.g. maybe even already in the broadphase) bullet uses the groups I don’t really know.

Just after that sentence, in the same section there is written:

“For example, for a click-to-select, you only care if the selection ray collides with a few selectable objects such as dropped weapons or powerups (one group), but not with non-selectables such as floors or walls (different group).”

I’m trying to use collision groups to make selective ray castings but I can’t find how to make it. I can add a rigidbody to a collision group and with a ray casting on the whole physics space, filter the desired bodies (those in the specified group) but I can’t find how to ray only that group so there is no need to manually filter it.
It is possible to do what I’m trying (ray cast only those objects in a collision group)?, if so, how would it be?

No, it doesn’t work for rays, rays don’t have collision groups.

Ok, thanks for the clarification, that example in the wiki then is a bit confusing. However, is it recommended to raycast over the whole physics space or over a node/array containing just the desired geometries/respectives bounding boxes? (having in mind 50-100 geometries). I don’t really know the difference on average efficiency between com.jme3.math.Ray and com.jme3.bullet.PhysicsSpace.rayTest.

Should be easy to test. I suggest basically implementing your game first and then doing micro optimization to see what your actual bottlenecks will be.

1 Like