Compare commits
4 Commits
bbe4ac4bc7
...
b76f44fcc7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b76f44fcc7 | ||
|
|
0ebfd839a7 | ||
|
|
d5a469314e | ||
|
|
8d086a02fe |
Binary file not shown.
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.
BIN
Content/Inputs/IA/IA_CameraRotateAction.uasset
LFS
Normal file
BIN
Content/Inputs/IA/IA_CameraRotateAction.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -10,12 +10,15 @@
|
||||
void ACameraPawn::CameraZoom(const FInputActionValue& Value)
|
||||
{
|
||||
auto f = Value.Get<float>();
|
||||
SpringArmComponent->TargetArmLength += f * 10.0f;
|
||||
SpringArmComponent->TargetArmLength = FMath::Clamp(SpringArmComponent->TargetArmLength, 300.0f, 3000.0f);
|
||||
SpringArmComponent->TargetArmLength += f * ZoomSpeed;
|
||||
SpringArmComponent->TargetArmLength = FMath::Clamp(SpringArmComponent->TargetArmLength, MinArmLength, MaxArmLength);
|
||||
}
|
||||
|
||||
void ACameraPawn::CameraRotate(const FInputActionValue& Value)
|
||||
{
|
||||
auto f = Value.Get<float>();
|
||||
FRotator r = FRotator(0.0f, f * RotateSpeed, 0.0f);
|
||||
AddActorWorldRotation(r);
|
||||
}
|
||||
|
||||
void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
||||
@@ -24,7 +27,14 @@ void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
||||
auto r = GetActorRightVector();
|
||||
auto f = r.Cross(FVector::UpVector);
|
||||
f.Normalize();
|
||||
SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f);
|
||||
SetActorLocation(GetActorLocation() + f * f2d.X * MoveSpeed + r * f2d.Y * MoveSpeed);
|
||||
}
|
||||
|
||||
void ACameraPawn::CameraReset(const FInputActionValue& Value)
|
||||
{
|
||||
SpringArmComponent->TargetArmLength = InitialArmLength;
|
||||
SetActorRotation(InitialRotation);
|
||||
SetActorRelativeLocation(FVector::ZeroVector);
|
||||
}
|
||||
|
||||
// Sets default values
|
||||
@@ -36,8 +46,8 @@ ACameraPawn::ACameraPawn()
|
||||
// 初始化 SpringArmComponent 和 CameraComponent
|
||||
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
|
||||
SpringArmComponent->SetupAttachment(RootComponent);
|
||||
SpringArmComponent->TargetArmLength = 1200.f;
|
||||
SpringArmComponent->bUsePawnControlRotation = true;
|
||||
SpringArmComponent->TargetArmLength = InitialArmLength;
|
||||
SpringArmComponent->bUsePawnControlRotation = true;// TODO: 何意味?
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
|
||||
|
||||
@@ -61,7 +71,11 @@ void ACameraPawn::BeginPlay()
|
||||
|
||||
// 附加到父物体
|
||||
this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform);
|
||||
|
||||
}
|
||||
|
||||
// 设置自身旋转
|
||||
SetActorRotation(InitialRotation);
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
|
||||
@@ -16,15 +16,32 @@ public:
|
||||
class USpringArmComponent* SpringArmComponent;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
class UCameraComponent* CameraComponent;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = "Camera")
|
||||
APawn* FollowTarget;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
FRotator InitialRotation = FRotator(-60.0f, 0.0f, 0.0f);
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float InitialArmLength = 1200.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float RotateSpeed = 2.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float ZoomSpeed =10.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float MoveSpeed = 10.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float MaxArmLength = 3000.0f;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||
float MinArmLength = 300.0f;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||
void CameraZoom(const FInputActionValue& Value);
|
||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||
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,14 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraZoomAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraZoom);
|
||||
}
|
||||
if (CameraResetAction)
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraResetAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraReset);
|
||||
}
|
||||
if (CameraRotateAction)
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraRotateAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraRotate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ public:
|
||||
class UInputAction* CameraMoveAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraZoomAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraResetAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraRotateAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
class TSubclassOf<class ACameraPawn> CameraActorClass;
|
||||
@@ -66,4 +70,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