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…