Establishing direction vector between two actors

I’m trying to check if actors within my TArray are standing within an imaginary cone in front of the player. It seems like the fastest way to do this would be to take the dot product of the player’s forward facing, and the vector from the player to the target. The former is easily done with FVector:DotProduct, but I can’t find a method for the latter- is one built in? I tried the following (as subtracting two locations should yield direction). but it gave me an angle of -1.#IND00, which doesn’t seem right:

float dProductAngle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(myActor->GetActorForwardVector(), (targetList[i]->GetActorLocation() - myActor->GetActorLocation()))));

This should be normalized:

(targetList[i]->GetActorLocation() - myActor->GetActorLocation())

Maybe (targetList[i]->GetActorLocation() - myActor->GetActorLocation()) returns 0,0,0 ? Their in the same position?

Beside use FMath::Acos instead of acosf.

Hmm, I normalized the subtraction and switched to Fmath::Acos, but it gives the result result. I get -1.#ND00 from every position I test it in, so I’m pretty sure it isn’t returning 0,0,0…

Current version:

float dProductAngle = FMath::RadiansToDegrees(acos(FVector::DotProduct(myActor->GetActorForwardVector(), (targetList[i]->GetActorLocation() - myActor->GetActorLocation().Normalize()))));

That’s my syntax problem, you’re right about the method… after fixing it, this works perfectly; thank you!

FVector normDirection = (targetList[i]->GetActorLocation() - myActor->GetActorLocation());
		float dProductAngle = FMath::RadiansToDegrees(acos(FVector::DotProduct(myActor->GetActorForwardVector(), normDirection)));

Beside use FMath::Acos instead of acos :wink: