Is there some way to find out if a vector world location is inside a collision box?

Basically what i’m wondering is if it’s currently possible to find out if a vector location is inside one or more collision boxes that are placed in the world.

What i need this for is that when my AI hears certain noises i want to be able to check if the location of this sound is within a certain collision/overlap box.

I have been looking around a bit but i cannot seem to find anything that could be used for this. Any help is appreciated.

I’m using the AI perception component for hearing, and as far as i know, there is no collision present at the sound location.

I was thinking of doing something like this but i thought i’d check if there was some way to avoid doing it like this.

The BoxCollision component has functions named IsOverlappingComponent and GetOverlappingComponents. If your sound generator Actor has a collision component, it could be used for testing if the box is overlapping it.
Also, there are the same functions aimed for Actors, instead of components. IsOverlappingActor and GetOverlappingActors.

Somehow, you know the sound location, correct? What if you moved some dummy collision sphere to this location and used it’s IsOverlappingXXX functions?
I’m not very familiar with the AI system yet.

Probably There’s some math that checks if a vector is inside a box, but I believe it won’t be simple in order to account for box rotations and it’d be very cumbersome to do in Blueprints. Unless you’re willing to write it in C++. But I don’t know the math… =(

Any clues yet? :slight_smile: The workaround I have on mind is to spawn actors for every location you want to check and then check if it’s in ‘IsOverlappingActor’ on your box.

I think i have something similar to what you are thinking about, but i chose not to create new actors for each check as this would be very expensive for what i was going to use it on. I instead put the function on my Gamemode and created a USphereComponent on the Gamemode that i move around.

bool AHomeInvasionGameMode::IsLocationOverlapping(FName Tag, FVector Location)
{
	if (OverlapSphere == nullptr)
		return false;

	// Move the sphere to the desired location that is going to be checked
	OverlapSphere->SetWorldLocation(Location);

	// Get all actors that are overlapping the sphere
	TArray<AActor*> OverlappingActors;
	OverlapSphere->GetOverlappingActors(OverlappingActors);

	// Loop through the array of actors and check the tags for the right one
	for (auto Itr(OverlappingActors.CreateConstIterator()); Itr; Itr++)
	{
		if ((*Itr) != nullptr && (*Itr)->ActorHasTag(Tag))
		{
			return true;
		}
	}
	
	// Move the component back to 0
	OverlapSphere->SetWorldLocation(FVector::ZeroVector);

	return false;
}

However i did also find functions that does things like this that can be used instead.

Hope this helps :slight_smile:

Ah yes, moving an actor/component will be better than spawning every time. I guess that I’ll implement something in this fashion too.

Thanks!