Angle between to points -- what am I missing?

Objective is to get the angle needed to rotate the character to face the mouse pointer. In 2d space this was no problem. Enter an Isometric camera (via boom like the top down game template) and things go nuts.

After some poking around and traveling down many wrong roads. I’ve reached this code:

void AShooterPlayerController::RotateToMouseCursor() {
	// get reference to controllers character
	ACharacter* pPawn = GetCharacter();
	if (!pPawn)
		return;

	FHitResult mouseHit = FHitResult();
	bool BMouseResult = GetHitResultUnderCursor(ECC_Visibility, true, mouseHit);

	FVector_NetQuantize MouseHitLoc = FVector_NetQuantize();
	if (BMouseResult)
	{
		MouseHitLoc = mouseHit.ImpactPoint;
		MouseHitLoc.Normalize();
		UE_LOG(LogShooter, Warning, TEXT("Hit Impact Point X: %f -- Y: %f -- Z: %f "), MouseHitLoc.X, MouseHitLoc.Y, MouseHitLoc.Z);

		FVector pPawnLoc = pPawn->GetActorLocation();
		pPawnLoc.Normalize();
		UE_LOG(LogShooter, Warning, TEXT("Pawn Loc X: %f -- Y: %f -- Z: %f "), pPawnLoc.X, pPawnLoc.Y, pPawnLoc.Z);

		float DotProduct = FVector::DotProduct(pPawnLoc, MouseHitLoc);
		float Radians = acosf(DotProduct);
		float AimAngle = FMath::RadiansToDegrees(Radians);

		UE_LOG(LogShooter, Warning, TEXT("AimAngle: %f"), AimAngle);

		pPawn->SetActorRotation(FRotator(0.f, AimAngle, 0.f));
	}
}

The value I get from:

float AimAngle = FMath::RadiansToDegrees(Radians);

Is not an identifiable angle in the sense of -180 to 180.

Am I overlooking a step in reaching my desired angle or is this actually a useful value and I’m just not realizing it?

http://s28.postimg.org/ktq4q2ai5/Untitled.png

Any pointers in the right direction will be welcome.

Your Dot product must be applied on different vectors. Here is the pseudo code to do it right:

DotProd = DotProduct(Pawn->ForwardVect.Normalize() , (MouseHit - Pawn->Location).Normalize())

22518-help.jpg

NOTE: I think actors have the property to access their forward vector (I don’t remember the exact name).

Ahh I see. I was trying to calculate the dot product off two points on the same vector.

float DotProduct = FVector::DotProduct(FVector(pPawn->GetActorForwardVector().Normalize()), FVector((MouseHitLoc - pPawnLoc).Normalize()));

Is more appropriate. I’ll play with this and update when/if I get it to work.

EDIT:
I was able to utilize your answer to solve for the proper dot product. Although this path did not lead me to the answer I was looking for, it did help me to understand enough to get there.

I was able to reach my objective by creating a vector from the player to the impact point of the mouse and then I set the players rotation to the rotation of this newly created vector. There was not a need to calculate the rotation between the players facing, and the object because the vector (straight line) from the player to the object already had the YAW rotation I needed.

Here is the final solution, maybe this can save someone else a week and half in the future (this does work with both orthogonal (top down) and isometric camera views:

void AShooterPlayerController::RotateToMouseCursor() {
	// get reference to controllers character
	ACharacter* pPawn = GetCharacter();
	if (!pPawn)
		return;

	// we use hit result of visibility to determine the mouse location in world space 
	FHitResult mouseHit = FHitResult();
	bool BMouseResult = GetHitResultUnderCursor(ECC_Visibility, true, mouseHit);

	// Create FVector MouseHitLoc to to store the Impact point of the location in world below the mouse
	FVector_NetQuantize MouseHitLoc = FVector_NetQuantize();

	// If we hit something set the location and update the rotation
	if (BMouseResult)
	{
		// Get the impact point of cursor in world space
		MouseHitLoc = mouseHit.ImpactPoint;

		// Get the player pawn location
		FVector pPawnLoc = pPawn->GetActorLocation(); // get the player pawn location

		// We create a new vector from the player to the mouse location
		FVector TargetVector = (MouseHitLoc - pPawnLoc); // create the vector from the player pawn to the mouse 
		TargetVector.Normalize();

		// We only care about rotation around the YAW axis
		FRotator targetRotation = FRotator(0.f, TargetVector.Rotation().Yaw, 0.f);
		
		// We set the characters facing to match the facing of the vector (so he looks at the mouse cursor)
		pPawn->SetActorRotation(targetRotation);
	}
}