Archive 17/01/2023.

SetCollisionEventMode seems to be static?

nergal

My case is that I want different type of instances of a class to either handle collision events or not. So based on a certain property I set the collision event mode such as this:

    if(type == constants::CHUNK_TYPE_WORLD) {
        body->SetCollisionEventMode(COLLISION_NEVER);
     } else {
        body->SetCollisionEventMode(COLLISION_ALWAYS);
    }

So if the type if a world it should not care about collision events, else it should listen for such.

But the problem that I experience is that whenever I set COLLISION_NEVER mask, it seems to apply for all bodies, not just the one I apply it for.

Are the collision masks applied to the body class and not just the instance?

Edit: It seems like collision events comes in bursts and not at every hit when I do the above if statement. But if I remove the COLLISION_NEVER mask it seems to be applied directly…strange?

Eugene

I did not understand anything, sorry.
But collision masks and layers are applied per body.

nergal

Sorry for my vague explanation.

I think I found my issue. If a body have COLLISION_ALWAYS and collides with a body that has COLLISION_NEVER the collision seems to never occur. Not even for the first body that has COLLISION_ALWAYS set.

Is this the expected behaviour?

Eugene

Yes.
Collision layer describes layers that the body belongs to,
Collision mask describes layers that the body collide.
If your body belongs to nowhere, it won’t collide at all.

jmiller

Here is one thread about collision masks/layers, if that might help. I also added an example there.

https://discourse.urho3d.io/t/how-do-you-choose-collision-masks-layers-solved/957

Modanung

This part of the PhysicsWorld uses the CollisionEventMode:

That’s the great thing about Urho being open source. Searching the code often clarifies. :slight_smile:

So indeed if any of the colliding bodies has the COLLISION_NEVER event mode no event should be signalled:

if (bodyA->GetCollisionEventMode() == COLLISION_NEVER || bodyB->GetCollisionEventMode() == COLLISION_NEVER)
    continue;
nergal

Thanks for all your input!

The only reason I set COLLISION_NEVER for some objects is to increase performance so that it’s not receiving any callbacks. Perhaps I’m performing too early optimisation? :slight_smile: