feat: 增加重置摄像头位置功能
This commit is contained in:
@@ -27,6 +27,13 @@ void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
||||
SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f);
|
||||
}
|
||||
|
||||
void ACameraPawn::CameraReset(const FInputActionValue& Value)
|
||||
{
|
||||
SpringArmComponent->TargetArmLength = 1200.0f;
|
||||
SetActorRotation(InitialRotation);
|
||||
SetActorRelativeLocation(FVector::ZeroVector);
|
||||
}
|
||||
|
||||
// Sets default values
|
||||
ACameraPawn::ACameraPawn()
|
||||
{
|
||||
@@ -61,7 +68,11 @@ void ACameraPawn::BeginPlay()
|
||||
|
||||
// 附加到父物体
|
||||
this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform);
|
||||
|
||||
}
|
||||
|
||||
// 设置自身旋转
|
||||
SetActorRotation(InitialRotation);
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
class UCameraComponent* CameraComponent;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
APawn* FollowTarget;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||
FRotator InitialRotation = FRotator(-60.0f, 0.0f, 0.0f);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||
void CameraZoom(const FInputActionValue& Value);
|
||||
@@ -25,6 +27,8 @@ public:
|
||||
void CameraRotate(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||
void CameraMove(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||
void CameraReset(const FInputActionValue& Value);
|
||||
|
||||
// Sets default values for this pawn's properties
|
||||
ACameraPawn();
|
||||
|
||||
@@ -69,6 +69,14 @@ void AMyCharacter::CameraZoom(const FInputActionValue& Value)
|
||||
}
|
||||
}
|
||||
|
||||
void AMyCharacter::CameraReset(const FInputActionValue& Value)
|
||||
{
|
||||
if (CameraActor)
|
||||
{
|
||||
CameraActor->CameraReset(Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets default values
|
||||
AMyCharacter::AMyCharacter()
|
||||
{
|
||||
@@ -98,7 +106,7 @@ void AMyCharacter::BeginPlay()
|
||||
}
|
||||
FTransform SpawnTransform(GetActorRotation(), GetActorLocation());
|
||||
temp = w->SpawnActorDeferred<ACameraPawn>(CameraClass, SpawnTransform);
|
||||
temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f));
|
||||
/*temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f));*/
|
||||
temp->FollowTarget = this;
|
||||
temp->FinishSpawning(SpawnTransform);
|
||||
}
|
||||
@@ -153,6 +161,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraZoomAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraZoom);
|
||||
}
|
||||
if (CameraResetAction)
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraResetAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraReset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
class UInputAction* CameraMoveAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraZoomAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraResetAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
class TSubclassOf<class ACameraPawn> CameraActorClass;
|
||||
@@ -66,4 +68,5 @@ private:
|
||||
void CameraZoom(const FInputActionValue& Value);
|
||||
void CameraRotate(const FInputActionValue& Value);
|
||||
void CameraMove(const FInputActionValue& Value);
|
||||
void CameraReset(const FInputActionValue& Value);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user