This week I worked on improving finding cover objects. The
first thing I did was to go back and tag all the cover seekable objects as
such. Without this, the problem is that objects such as walls and such might be
detected as cover objects as they satisfy the width and height requirements.
Then, I stuck with the sphere trace implementation where a
sphere cast would be performed to find the closest cover object. I compared the
tag and found the closest one. Then, I changed the implementation to use Seek
rather than Arrive, as realistically one wouldn’t slow down going into cover.
This also removed some visual artifacts I was having with very slow movement
over small distances with Arrive. The updated code to find the best hiding spot
looks like this:
if (UKismetSystemLibrary::SphereTraceMulti(
GetWorld(),
pOwner->GetActorLocation(),
pOwner->GetActorLocation(),
CoverSearchRadius,
TQuery,
false,
ActorsToIgnore,
EDrawDebugTrace::ForOneFrame,
OutHits,
true))
{
// Find
closest object
FHitResult ClosestHit;
ClosestHit.Distance = CoverSearchRadius;
for (auto Hit : OutHits)
{
// Make sure object is not under me or over me
if (Hit.GetActor()->ActorHasTag(CoverTag) && Hit.Distance < ClosestHit.Distance && IsHiddenBy(Hit.GetActor()))
{
ClosestHit = Hit;
}
}
if (ClosestHit.GetActor())
{
// Seek works better than Arrive here, and also it's probably
better
// since one won't "arrive" to a hiding spot - you'll
probably run
// full velocity there
return Seek(GetHidingSpot(ClosestHit.GetActor(), Target->GetActorLocation()));
}
}
return Evade(Target);
Now, there are a few things to consider. The closest cover
object might not actually have the closest hiding spot. In that case, should we
calculate all the hiding spots of nearby objects and then get the closest
hiding spot from that? Might that be a little expensive? These are all
questions to be answered.
Next, I started implementing my own Pathfinding. However,
this proved to be more frustrating than expected, owing to the fact that Unreal
doesn’t have it’s native implementation of Navigation yet, it uses
Recast/Detour, and converting back and forth between the two systems is quite a
pain. In order for me to create the navigation graph myself, I would have to
implement a bounding volume and point detection inside of that myself, and that
seems rather out of the scope of this project.
I’m currently trying to integrate my implementation with the
existing interfaces, and that is proving to be taking a long time.
Find the source code here: https://github.com/GTAddict/UnrealAIPlugin/
Find the source code here: https://github.com/GTAddict/UnrealAIPlugin/
Comments