Download

How to calculate camera and character rotation difference to use AddControllerYawInput?

I use the 3rd person template on witch I added a free camera mode that activate and deactivate on the press and the release of a button. I added the 2 fallowing function in my character class to do so.



void AATPreProtoCharacter::CameraOnly()
{
	bUseControllerRotationYaw = false;
}

void AATPreProtoCharacter::StopCameraOnly()
{
	bUseControllerRotationYaw = true;
}


It work great, except for one little detail, when the button is release the character immediately rotate to where the camera is pointing. But what i want is the opposite, the camera to rotate back to where the character is pointing.

After some search on the forum I came with the fallowing solution (point the camera back to the character rotation with the AddControllerYawInput function), but can’t figure out how to make it work (how to calculate the float from the character and the camera rotation), all it dose is rotating the character and the camera in a “random” rotation.



void AATPreProtoCharacter::StopCameraOnly()
{
        if (Controller != NULL) 
	{
		const FRotator CameraRotation = CameraBoom->GetComponentRotation();
		const FRotator ActorRotation = GetActorRotation();
		/* 
                const FRotator TempRotation(0.f, 90.0f, 0.f);
		
		FQuat AQuat = FQuat(ActorRotation);
		FQuat BQuat = FQuat(TempRotation);

		const FRotator NewRotation(BQuat*AQuat);
                */

		FRotator TargetRotation = ActorRotation - CameraRotation;
		TargetRotation.Normalize();

		AddControllerYawInput(TargetRotation.Yaw);
	}

	bUseControllerRotationYaw = true;
}


So can some one help me understand how to calculate this float parameter from rotation to point in the right direction? Or maybe I just use the wrong getter to have the right value to begin with?

P.S: Please any one, I’m kind of stock here, it’s my second post about this…

Have you tried just outright setting the camera’s rotation to the player’s rotation? I’m not sure AddControllerYawInput is what you want (but I could be wrong).

i.e. CameraBoom->SetWorldRotation(GetActorRotation());

I tried it and it don’t work, the thing only act like the line change nothing, the character rotate to current camera position.

void AATPreProtoCharacter::StopCameraOnly()
{
CameraBoom->SetWorldRotation(GetActorRotation());
bUseControllerRotationYaw = true;
}

Any one have a idea how to calculate the float to use AddControllerYawInput(float) to have my camera align with the character rotation instead of the opposite (calculate the float from Character and CameraBoom rotation different??)?