feat: 摄像头移动
This commit is contained in:
Binary file not shown.
BIN
Content/Inputs/IA/IA_CameraMoveAction.uasset
LFS
Normal file
BIN
Content/Inputs/IA/IA_CameraMoveAction.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -18,8 +18,9 @@ void ACameraPawn::CameraRotate(const FInputActionValue& Value)
|
||||
void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
||||
{
|
||||
auto f2d = Value.Get<FVector2D>();
|
||||
auto f = GetActorForwardVector();
|
||||
auto r = GetActorRightVector();
|
||||
auto f = r.Cross(FVector::UpVector);
|
||||
f.Normalize();
|
||||
SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,30 @@ void AMyCharacter::StopCrouch(const FInputActionValue& Value)
|
||||
UE_LOG(LogTemp, Warning, TEXT("Stop Crouch"));
|
||||
}
|
||||
|
||||
void AMyCharacter::CameraMove(const FInputActionValue& Value)
|
||||
{
|
||||
if (CameraActor)
|
||||
{
|
||||
CameraActor->CameraMove(Value);
|
||||
}
|
||||
}
|
||||
|
||||
void AMyCharacter::CameraRotate(const FInputActionValue& Value)
|
||||
{
|
||||
if (CameraActor)
|
||||
{
|
||||
CameraActor->CameraRotate(Value);
|
||||
}
|
||||
}
|
||||
|
||||
void AMyCharacter::CameraZoom(const FInputActionValue& Value)
|
||||
{
|
||||
if (CameraActor)
|
||||
{
|
||||
CameraActor->CameraZoom(Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets default values
|
||||
AMyCharacter::AMyCharacter()
|
||||
{
|
||||
@@ -63,22 +87,21 @@ void AMyCharacter::BeginPlay()
|
||||
ACameraPawn* temp = nullptr;
|
||||
if (w)
|
||||
{
|
||||
UClass* CameraClass;
|
||||
if (CameraActorClass)
|
||||
{
|
||||
FTransform SpawnTransform(GetActorRotation(), GetActorLocation());
|
||||
temp = w->SpawnActorDeferred<ACameraPawn>(CameraActorClass, SpawnTransform);
|
||||
temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f));
|
||||
temp->FollowTarget = this;
|
||||
temp->FinishSpawning(SpawnTransform);
|
||||
CameraClass = CameraActorClass;
|
||||
}
|
||||
else
|
||||
{
|
||||
CameraClass = ACameraPawn::StaticClass();
|
||||
}
|
||||
FTransform SpawnTransform(GetActorRotation(), GetActorLocation());
|
||||
temp = w->SpawnActorDeferred<ACameraPawn>(ACameraPawn::StaticClass(), SpawnTransform);
|
||||
temp = w->SpawnActorDeferred<ACameraPawn>(CameraClass, SpawnTransform);
|
||||
temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f));
|
||||
temp->FollowTarget = this;
|
||||
temp->FinishSpawning(SpawnTransform);
|
||||
}
|
||||
}
|
||||
if (temp)
|
||||
{
|
||||
CameraActor = temp;
|
||||
@@ -122,6 +145,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch);
|
||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch);
|
||||
}
|
||||
if (CameraMoveAction)
|
||||
{
|
||||
EnhancedInputComponent->BindAction(CameraMoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
class UInputAction* RunAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CrouchAction;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* CameraMoveAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||
class TSubclassOf<class ACameraPawn> CameraActorClass;
|
||||
@@ -58,4 +60,8 @@ private:
|
||||
|
||||
UPROPERTY(VisibleInstanceOnly, Category = "Camera")
|
||||
class ACameraPawn* CameraActor;
|
||||
|
||||
void CameraZoom(const FInputActionValue& Value);
|
||||
void CameraRotate(const FInputActionValue& Value);
|
||||
void CameraMove(const FInputActionValue& Value);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user