Download

PawnSensing vs AIPerception vs custom code ?

So i need to implement something so my AI can see the player.

1) Pawn Sensing Component, Very limited and i was told that it’s outdated and i should use the new AI Perception Component instead.

2) AI Perception Component, Has been in development for a while at epic but is still extremely buggy and documentation is minimal at best making it hard to understand.

3) Custom code solution, When i was investigating what AI sensing component RoboRecall used in their mod kit, I found that they don’t use either of the two iv’e listed above
and instead use the custom code below:



// is target within our vision cone?
FVector const ToTargetNorm = (TraceEnd - ViewLoc).GetSafeNormal();
FVector const EyesForwardNorm = ViewRotation.Vector();
float const AngleCos = FVector::DotProduct(ToTargetNorm, EyesForwardNorm);
float const CosLimit = FMath::Cos(FMath::DegreesToRadians(AIVisionAngle));

if (bDrawDebugVisionCone)
{
	DrawDebugCone(World, ViewLoc, EyesForwardNorm, 300.f, FMath::DegreesToRadians(AIVisionAngle), FMath::DegreesToRadians(AIVisionAngle), 12, FColor::Yellow, false, 1.f);
}

bInVisionCone = (AngleCos >= CosLimit);


Question: So which one should i use? Is there something i’m missing?

Depends what you need.

  1. Will just tell you if an agent can see a target. If that’s all you need to know, great, use that.

  2. The AI Perception Component is more complex. It’ll track multiple perceived actors, has a ‘memory’ features so the agent doesn’t immediately forget a target if it goes round a corner etc, various configurable options. Also support not just sight perception, but hearing as well (and another sense IIRC).