I have an object with a child object, each has a PhysicsShape. The parent object has a PhysicsBody.
I would like, at runtime (i.e. after instantiating a clone of the converted entity) to set a collision filter on all the colliders. (in fact, at conversion time, I already define some specific belongs to / collides with values, and at runtime want to add a unique GroupIndex to each)
Somehow, only the parent entity has a PhysicsCollider. There seem to be sub-colliders, but I don’t understand how to get the ColliderKey that would be needed to access one.
Do I need to generate them as Force Unique?
Somehow the object seems to also not collide as expected (i.e. the belongs to / collides with values seem to get changed - isn’t having multiple filters on one entity possible?)
elaborateneargemsbuck
(illustration video, the collision filters are so the ship can launch missiles and projectiles from within its body / hull / shield colliders; the “mesh” on the shield is temporary because the convex hull generation usually stalls out)
1 Like
I suppose to solve the bullets problem, I can run disable the Broadphase pairs appropriately.
What would be interesting is, can I disable one of the colliders in a composite collider?
Ok, works like a charm with the Broadphase. I do need to sort out some physics issues post-collision event now. (not visible in video)
[BurstCompile]
private struct DisablePairsJob : IBodyPairsJob
{
[ReadOnly] public ComponentDataFromEntity<Owner> Owners;
public unsafe void Execute(ref ModifiableBodyPair pair)
{
// Disable the pair if one owns the other
var a = pair.Entities.EntityA;
var b = pair.Entities.EntityB;
if (Owners.Exists(a))
{
if (Owners[a].entity == b) pair.Disable();
}
else if (Owners.Exists(b))
{
if (Owners[b].entity == a) pair.Disable();
}
}
}
grimfainthorseshoebat
2 Likes
The “weird collision” problem was me accidentally not removing the static meshcollider off a quad I was converting and spawning 
Works really great. Now to find out how to turn on and off colliders (like for the shield) efficiently. Probably also with the pairs job.
1 Like