Compare commits
9 Commits
dev
...
bbe4ac4bc7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbe4ac4bc7 | ||
|
|
877beaa3f5 | ||
|
|
d86b3f53a9 | ||
|
|
402a0fed99 | ||
|
|
746a85ae31 | ||
|
|
166198c3e3 | ||
|
|
5d2c3534cc | ||
|
|
d47d390dbb | ||
|
|
8c91acd3d8 |
@@ -53,4 +53,3 @@ ManualIPAddress=
|
|||||||
|
|
||||||
[/Script/UnrealBuildTool.UnrealBuildTool]
|
[/Script/UnrealBuildTool.UnrealBuildTool]
|
||||||
bAllowGitCommandlineIntegration=False
|
bAllowGitCommandlineIntegration=False
|
||||||
|
|
||||||
|
|||||||
BIN
Content/Blueprints/BP_CameraPawn.uasset
LFS
Normal file
BIN
Content/Blueprints/BP_CameraPawn.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
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.
BIN
Content/Inputs/IA/IA_CameraZoomAction.uasset
LFS
Normal file
BIN
Content/Inputs/IA/IA_CameraZoomAction.uasset
LFS
Normal file
Binary file not shown.
Binary file not shown.
BIN
Content/地图关卡/Map_City.umap
LFS
BIN
Content/地图关卡/Map_City.umap
LFS
Binary file not shown.
80
Source/lonese/CameraPawn.cpp
Normal file
80
Source/lonese/CameraPawn.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "CameraPawn.h"
|
||||||
|
|
||||||
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
|
#include "InputActionValue.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACameraPawn::CameraRotate(const FInputActionValue& Value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
||||||
|
{
|
||||||
|
auto f2d = Value.Get<FVector2D>();
|
||||||
|
auto r = GetActorRightVector();
|
||||||
|
auto f = r.Cross(FVector::UpVector);
|
||||||
|
f.Normalize();
|
||||||
|
SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets default values
|
||||||
|
ACameraPawn::ACameraPawn()
|
||||||
|
{
|
||||||
|
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
// 初始化 SpringArmComponent 和 CameraComponent
|
||||||
|
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
|
||||||
|
SpringArmComponent->SetupAttachment(RootComponent);
|
||||||
|
SpringArmComponent->TargetArmLength = 1200.f;
|
||||||
|
SpringArmComponent->bUsePawnControlRotation = true;
|
||||||
|
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||||
|
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
|
||||||
|
|
||||||
|
// 设置弹簧臂碰撞属性
|
||||||
|
SpringArmComponent->bDoCollisionTest = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
void ACameraPawn::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
if (FollowTarget)
|
||||||
|
{
|
||||||
|
// 切换到当前摄像头
|
||||||
|
auto c = Cast<APlayerController>(FollowTarget->GetController());
|
||||||
|
if (c)
|
||||||
|
{
|
||||||
|
c->SetViewTarget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 附加到父物体
|
||||||
|
this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
void ACameraPawn::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called to bind functionality to input
|
||||||
|
void ACameraPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||||
|
{
|
||||||
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
43
Source/lonese/CameraPawn.h
Normal file
43
Source/lonese/CameraPawn.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/Pawn.h"
|
||||||
|
#include "CameraPawn.generated.h"
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class LONESE_API ACameraPawn : public APawn
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
class USpringArmComponent* SpringArmComponent;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
class UCameraComponent* CameraComponent;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
APawn* FollowTarget;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Sets default values for this pawn's properties
|
||||||
|
ACameraPawn();
|
||||||
|
// Called every frame
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
// Called to bind functionality to input
|
||||||
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
|
|
||||||
|
#include "CameraPawn.h"
|
||||||
|
|
||||||
void AMyCharacter::Move(const FInputActionValue& Value)
|
void AMyCharacter::Move(const FInputActionValue& Value)
|
||||||
{
|
{
|
||||||
auto f2d = Value.Get<FVector2D>();
|
auto f2d = Value.Get<FVector2D>();
|
||||||
@@ -43,6 +45,30 @@ void AMyCharacter::StopCrouch(const FInputActionValue& Value)
|
|||||||
UE_LOG(LogTemp, Warning, TEXT("Stop Crouch"));
|
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
|
// Sets default values
|
||||||
AMyCharacter::AMyCharacter()
|
AMyCharacter::AMyCharacter()
|
||||||
{
|
{
|
||||||
@@ -57,6 +83,29 @@ void AMyCharacter::BeginPlay()
|
|||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
auto w = GetWorld();
|
||||||
|
ACameraPawn* temp = nullptr;
|
||||||
|
if (w)
|
||||||
|
{
|
||||||
|
UClass* CameraClass;
|
||||||
|
if (CameraActorClass)
|
||||||
|
{
|
||||||
|
CameraClass = CameraActorClass;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CameraClass = ACameraPawn::StaticClass();
|
||||||
|
}
|
||||||
|
FTransform SpawnTransform(GetActorRotation(), GetActorLocation());
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
@@ -96,6 +145,14 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
|
|||||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch);
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AMyCharacter::BeginCrouch);
|
||||||
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch);
|
EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AMyCharacter::StopCrouch);
|
||||||
}
|
}
|
||||||
|
if (CameraMoveAction)
|
||||||
|
{
|
||||||
|
EnhancedInputComponent->BindAction(CameraMoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraMove);
|
||||||
|
}
|
||||||
|
if (CameraZoomAction)
|
||||||
|
{
|
||||||
|
EnhancedInputComponent->BindAction(CameraZoomAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraZoom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ public:
|
|||||||
class UInputAction* RunAction;
|
class UInputAction* RunAction;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
class UInputAction* CrouchAction;
|
class UInputAction* CrouchAction;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
|
class UInputAction* CameraMoveAction;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
|
class UInputAction* CameraZoomAction;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
class TSubclassOf<class ACameraPawn> CameraActorClass;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
void Move(const FInputActionValue& Value);
|
void Move(const FInputActionValue& Value);
|
||||||
@@ -52,4 +59,11 @@ protected:
|
|||||||
private:
|
private:
|
||||||
bool bIsRunning = false;
|
bool bIsRunning = false;
|
||||||
bool bIsCrouching = false;
|
bool bIsCrouching = false;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleInstanceOnly, Category = "Camera")
|
||||||
|
class ACameraPawn* CameraActor;
|
||||||
|
|
||||||
|
void CameraZoom(const FInputActionValue& Value);
|
||||||
|
void CameraRotate(const FInputActionValue& Value);
|
||||||
|
void CameraMove(const FInputActionValue& Value);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
{
|
{
|
||||||
"Name": "lonese",
|
"Name": "lonese",
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "Default"
|
"LoadingPhase": "Default",
|
||||||
|
"AdditionalDependencies": [
|
||||||
|
"Engine"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Plugins": [
|
"Plugins": [
|
||||||
@@ -24,11 +27,8 @@
|
|||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"SupportedTargetPlatforms": [
|
"SupportedTargetPlatforms": [
|
||||||
"Win64"
|
"Win64"
|
||||||
|
],
|
||||||
|
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/362651520df94e4fa65492dbcba44ae2"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"TargetPlatforms": [],
|
|
||||||
"AdditionalRootDirectories": [],
|
|
||||||
"AdditionalPluginDirectories": [],
|
|
||||||
"EpicSampleNameHash": ""
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user