Hi. I have written the following functions on my enemy character in order to be able to see my hero character but it can see the hero even if it is not facing the hero character . it is because I set the End_Trace location as my hero character location. now I want to put something like a condition to see if my enemy character is facing toward the hero or to check an angle as an angle sight or something and then do tracing.
can anybody help me with it?
void AEnemyBot::See()
{
FVector EyeLocation = GetMesh()->GetSocketLocation("Eye");
FVector Start_Trace = EyeLocation;
FVector End;
ASwatCharacter* Swat = Cast<ASwatCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));
if(Swat)
{
FVector End_Trace = Swat->GetActorLocation();
End = End_Trace;
}
const FHitResult Impact = Detect(Start_Trace, End);
ProcessDetect(Impact, Start_Trace, End);
}
FHitResult AEnemyBot::Detect(FVector Start_Trace, FVector End_Trace)
{
FCollisionQueryParams TraceParams(FName(""), true, this);
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
TraceParams.bTraceComplex = true;
FHitResult Hit(ForceInit);
GetWorld()->LineTraceSingleByChannel(Hit, Start_Trace, End_Trace, TRACE_WEAPON, TraceParams);
DrawDebugLine(this->GetWorld(), Start_Trace, End_Trace, FColor::Blue, true, 1000, 10.f);
return Hit;
}
void AEnemyBot::ProcessDetect(const FHitResult & Impact, const FVector & Orgin, const FVector End)
{
const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : End;
DrawDebugLine(this->GetWorld(), Orgin, EndPoint, FColor::Yellow, true, 1000, 10.f);
}