.cpp
void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (_bAltPressed) //Tick to call sync the character in real time
{
SynchCharacterFreeLook();
}
}
void AMyCharacter::SynchCharacterFreeLook()
{
print("Synch free look"); //called print on screen macro
FRotator rotYaw_GC = GetControlRotation();
FRotator rotYaw_GA = GetActorRotation();
rotYaw_GA.Yaw = rotYaw_GC.Yaw;
SetActorRotation(rotYaw_GA);
}
PlayerInputComponent->BindAction(FreeLook, IE_Pressed, this, &AMyCharacter::FreeLookPressed);
PlayerInputComponent->BindAction(FreeLook, IE_Released, this, &AMyCharacter::FreeLookReleased);
void AMyCharacter::FreeLookPressed() //Alt Pressed
{
_bAltPressed = true;
FRotator AltPressedRotation = SpringArm->GetTargetRotation();
GetCharacterMovement()->bUseControllerDesiredRotation = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
}
void AMyCharacter::FreeLookReleased() //Alt Released
{
_bAltPressed = false;
FRotator AltPressedRotation = SpringArm->GetTargetRotation();
GetCharacterMovement()->bUseControllerDesiredRotation = true;
GetCharacterMovement()->bOrientRotationToMovement = false;
}