How not to trace if it is not the expected rotation even if the end_trace is set as a specific actor location?

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 :smiley: . 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);
}

Hey -

Rather than make your player location the end location for the trace it would be best to find the forward vector from your start location and trace out a set distance that the enemy can “see”. Then cast whatever the trace hit to your character to see if the hit actor is the player.

Cheers

how can I get the direction from my enemy character to my player character?
i mean i want to find out which direction leads the trace move to my player character? then i can set a distance that the enemy can see.
so, that specific direction must be updated every tick

maybe the enemy is next to the player but the trace direction is somewhere else :smiley: