Archive 17/01/2023.

Raycast collision filtering problem

Yatsomi

Hi to all, im using RayCastSingle() in PhysicsWorld2D.cpp, but i have problem with collision filtering, here is my code:

define categories:

enum GAMELAYERS : const unsigned {
None = 0,
Character = 0x0002 ,
Platforms = 0x0004,
};

set character category bits:

boxCollider_ = GetNode()->CreateComponent();
boxCollider_->SetCategoryBits(GAMELAYERS::Character);
rigidbody_ = GetNode()->CreateComponent();

and raycast:

physicsWorld_->RaycastSingle(results, startPos, endPos, GAMELAYERS::Platforms);

i send platform bits as raycast collisionmask, but it still hit my character. i dont get it.
box2D collision filtering use this method:

uint16 catA = fixtureA.filter.categoryBits;
uint16 maskA = fixtureA.filter.maskBits;
uint16 catB = fixtureB.filter.categoryBits;
uint16 maskB = fixtureB.filter.maskBits;
if ((catA & maskB) != 0 && (catB & maskA) != 0)
{
// fixtures can collide
}

0x0002 & 0x0004 == 0
so whats the problem?
am i misunderstood how Category/Mask collision filtering works?

Sinoid

It’s a bug.

CollisionShape2D::CreateFixture() needs to set the filter data on the fixture, it currently doesn’t. So you can only set those category/mask bits if you follow the sequence of Create Rigidbody -> Create shape -> setup shapes size and physical traits -> set category/mask bits

Yatsomi

Hi Siniod, i submit an issue on git, lets see what they say about it.

Sinoid

Well I’m probably wrong. I don’t use Urho2D - that’s just the suspect stuff I see. I wouldn’t be surprised if deep down it’s a Box2D problem.