Say I have two actor A and B, I want to know if there is a way to detect that A is TOTALLY inside B.
I know OnComponentBeginOverlap will be fired when two components begin overlapping, but I have no idea with detecting “A inside B”.
Any help would be greatly appreciated!
Check out AActor::GetActorBounds and FBox, specifically IsInside.
AActor* Actor1, Actor2;
FVector Origin1, Extent1;
FVector Origin2, Extent2;
bool bOnlyCollidingComponents = false; // set to true if you want only colliding components
Actor1->GetActorBounds(bOnlyCollidingComponents, Origin1, Extent1);
Actor2->GetActorBounds(bOnlyCollidingComponents, Origin2, Extent2);
FBox ActorBounds1(Origin1, Extent1);
FBox ActorBounds2(Origin2, Extent2);
if (ActorBounds1.IsInside(ActorBounds2)
{
// then Actor2 is fully inside Actor1
}
else if (ActorBounds2.IsInside(ActorBounds1)
{
// then Actor1 is fully inside Actor2
}
Sorry for replying late. Your answer fixed my issue. Thanks a lot !
Vahid
(Vahid)
4
It’s safer to create box like this:
FVector Origin1, Extent1, Origin2, Extent2;
Actor1->GetActorBounds(false, Origin1, Extent1);
Actor2->GetActorBounds(false, Origin2, Extent2);
FBox BoxBounds1(Origin1 - Extent1, Origin1 + Extent1);
FBox BoxBounds1(Origin2 - Extent2, Origin2 + Extent2);
if (BoxBounds1.IsInside(BoxBounds2)
{
// then Actor2 is fully inside Actor1
}
else if (BoxBounds2.IsInside(BoxBounds1)
{
// then Actor1 is fully inside Actor2
}