Implement camera perspective toggle
This commit is contained in:
@@ -43,7 +43,7 @@ AAgrarianGameCharacter::AAgrarianGameCharacter()
|
||||
// Create a camera boom (pulls in towards the player if there is a collision)
|
||||
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
|
||||
CameraBoom->SetupAttachment(RootComponent);
|
||||
CameraBoom->TargetArmLength = 400.0f;
|
||||
CameraBoom->TargetArmLength = ThirdPersonCameraDistance;
|
||||
CameraBoom->bUsePawnControlRotation = true;
|
||||
|
||||
// Create a follow camera
|
||||
@@ -80,6 +80,11 @@ void AAgrarianGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerIn
|
||||
{
|
||||
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this, &AAgrarianGameCharacter::Interact);
|
||||
}
|
||||
|
||||
if (ToggleCameraAction)
|
||||
{
|
||||
EnhancedInputComponent->BindAction(ToggleCameraAction, ETriggerEvent::Started, this, &AAgrarianGameCharacter::ToggleCameraPerspective);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,6 +115,46 @@ void AAgrarianGameCharacter::Interact()
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::ToggleCameraPerspective()
|
||||
{
|
||||
SetFirstPersonCamera(!bFirstPersonCamera);
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::SetFirstPersonCamera(bool bEnableFirstPerson)
|
||||
{
|
||||
bFirstPersonCamera = bEnableFirstPerson;
|
||||
|
||||
if (!CameraBoom || !FollowCamera)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (bFirstPersonCamera)
|
||||
{
|
||||
CameraBoom->TargetArmLength = 0.0f;
|
||||
CameraBoom->SocketOffset = FirstPersonCameraOffset;
|
||||
CameraBoom->bDoCollisionTest = false;
|
||||
FollowCamera->bUsePawnControlRotation = false;
|
||||
|
||||
if (GetMesh())
|
||||
{
|
||||
GetMesh()->SetOwnerNoSee(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CameraBoom->TargetArmLength = ThirdPersonCameraDistance;
|
||||
CameraBoom->SocketOffset = FVector::ZeroVector;
|
||||
CameraBoom->bDoCollisionTest = true;
|
||||
FollowCamera->bUsePawnControlRotation = false;
|
||||
|
||||
if (GetMesh())
|
||||
{
|
||||
GetMesh()->SetOwnerNoSee(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianGameCharacter::DoMove(float Right, float Forward)
|
||||
{
|
||||
if (GetController() != nullptr)
|
||||
|
||||
Reference in New Issue
Block a user