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