SphereSweepTrace getting area of hit.

I’m doing 3rd person combat. I need to figure out what side a weapon has hit the enemy (front, back, left or right). I’m doing this by getting the angle between the other character’s forward vector and the impact normal of the hitresult. I’m using SweepSingleByChannel with a sphere to get the hit result. I do something like this.



FVector HitActorDirection = HitResult.GetActor()->GetMesh()->GetForwardVector();
FVector ImpactNormal = HitResult.ImpactNormal;

float angle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(HitActorDirection, -ImpactNormal)));
UE_LOG(LogTemp, Warning, TEXT("angle is %f"), angle);


But for some reason, the angles don’t make sense. They are all between -90 and 70ish. I’m just trying to figure out if I’m hitting the enemy from the front or behind. How can I get the side of where I hit?
I negated the impact normal because I read that the normal faces the center of the sphere so I have to face it the opposite direction. I tried not negating it and the angle result made less sense…

Nvm, I found a much easier solution. I could just get both actor’s forward vector and use that angle to determine where the attack is coming from. Can’t believe I didn’t think of it earlier lol.
Here’s the solution if anyone want to use this in the future.



ACharacter *HitActorClass = Cast<ACharacter>(HitResult.GetActor());

FVector HitActorDirection = HitActorClass->GetMesh()->GetForwardVector();
FVector OwnerActorDirection = GetOwner()->GetMesh()->GetForwardVector();

float angle = FMath::RadiansToDegrees(acosf(FVector::DotProduct(HitActorDirection, OwnerActorDirection)));
UE_LOG(LogTemp, Warning, TEXT("angle is %f"), angle);