Hi, everyone!
I testing my custom collision filter through FContactModifyCallback. In my testing, The character added itself to the bomb’s filter list on the bomb be spawning. My contact modifies callback checking the filter list and ignore the contact if the character in the bomb’s filter list. This worked if the bomb hasn’t dropped on the ground. On the bomb dropped on the ground, The character’s location has been adjusting forced, And the character will not be able to walk through the bomb. How fix it? Thanks!
void onContactModify(PxContactModifyPair* const pairs, PxU32 count)
{
for (PxU32 i = 0; i < count; i++)
{
PxContactModifyPair& pair = pairs[i];
for (PxU32 j = 0; j < pair.contacts.size(); j++)
{
const FBodyInstance* bodyInst1 = FPhysxUserData::Get<FBodyInstance>(pair.actor[0]->userData);
if (!bodyInst1)
{
UE_LOG(LogTemp, Error, TEXT("!bodyInst1"))
continue;
}
AActor* actor1 = bodyInst1->OwnerComponent->GetOwner();
const FBodyInstance* bodyInst2 = FPhysxUserData::Get<FBodyInstance>(pair.actor[1]->userData);
if (!bodyInst2)
{
UE_LOG(LogTemp, Error, TEXT("!bodyInst2"))
continue;
}
AActor* actor2 = bodyInst2->OwnerComponent->GetOwner();
assert(actor1 && actor2);
ABombBase* bomb = nullptr;
bomb = dynamic_cast<ABombBase*>(actor1);
if (bomb != nullptr)
{
assert(dynamic_cast<Atest2Character*>(actor2));
if (bomb->isCollisionIgnoreActor(actor2))
{
UE_LOG(LogTemp, Error, TEXT("isCollisionIgnoreActor1"))
pair.contacts.ignore(j);
}
}
else
{
bomb = dynamic_cast<ABombBase*>(actor2);
if (bomb != nullptr)
{
assert(dynamic_cast<Atest2Character*>(actor1));
if (bomb->isCollisionIgnoreActor(actor1))
{
UE_LOG(LogTemp, Error, TEXT("isCollisionIgnoreActor2"))
pair.contacts.ignore(j);
}
}
}
}
}
}