Minor - Déplace la caméra vers le PlayerPawn - V01.04.00
Transfère la logique de la caméra du PlayerController vers le PlayerPawn. Cela permet un meilleur contrôle et une association plus directe de la caméra avec le pawn contrôlé. Ajuste également les chemins de fichiers dans les macros pour une meilleure organisation.
This commit is contained in:
@@ -6,28 +6,14 @@
|
|||||||
|
|
||||||
AM4_PlayerController::AM4_PlayerController()
|
AM4_PlayerController::AM4_PlayerController()
|
||||||
{
|
{
|
||||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
PrimaryActorTick.bCanEverTick = false;
|
||||||
CameraComponent->ProjectionMode = ECameraProjectionMode::Orthographic;
|
PrimaryActorTick.bStartWithTickEnabled = false;
|
||||||
CameraComponent->OrthoWidth = 2048.0f;
|
|
||||||
CameraComponent->SetAspectRatio(160.0f/192.0f);
|
|
||||||
|
|
||||||
// attach the camera to the controller's root component
|
|
||||||
CameraComponent->SetupAttachment(GetRootComponent());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AM4_PlayerController::BeginPlay()
|
void AM4_PlayerController::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
if (CameraComponent)
|
|
||||||
{
|
|
||||||
CameraComponent->SetRelativeLocation(FVector(0, 0, 1000));
|
|
||||||
CameraComponent->SetRelativeRotation(FRotator(-90.0f, 0.0f, 0.0f));
|
|
||||||
|
|
||||||
// Set the camera as the view target
|
|
||||||
SetViewTarget(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GetLocalPlayer())
|
if (!GetLocalPlayer())
|
||||||
{
|
{
|
||||||
@@ -105,13 +91,4 @@ void AM4_PlayerController::Move(const FInputActionValue& Value)
|
|||||||
void AM4_PlayerController::OnPossess(APawn* InPawn)
|
void AM4_PlayerController::OnPossess(APawn* InPawn)
|
||||||
{
|
{
|
||||||
Super::OnPossess(InPawn);
|
Super::OnPossess(InPawn);
|
||||||
|
|
||||||
PRINT_SCREEN(TEXT("PlayerController Possess"), FColor::Green);
|
|
||||||
|
|
||||||
if (InPawn && CameraComponent)
|
|
||||||
{
|
|
||||||
CameraComponent->AttachToComponent(InPawn->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
|
|
||||||
CameraComponent->SetRelativeLocation(FVector(0, 0, 1000));
|
|
||||||
CameraComponent->SetRelativeRotation(FRotator(-90.0f, 0.0f, 0.0f));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,14 @@ AM4_PlayerPawn::AM4_PlayerPawn()
|
|||||||
MeshComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f));
|
MeshComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f));
|
||||||
MeshComponent->SetupAttachment(RootComponent);
|
MeshComponent->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||||
|
CameraComponent->ProjectionMode = ECameraProjectionMode::Orthographic;
|
||||||
|
CameraComponent->OrthoWidth = 2048.0f;
|
||||||
|
CameraComponent->SetAspectRatio(160.0f/192.0f);
|
||||||
|
CameraComponent->SetupAttachment(RootComponent);
|
||||||
|
CameraComponent->SetRelativeLocation(FVector(0,0,1000));
|
||||||
|
CameraComponent->SetRelativeRotation(FRotator(-90.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
LoadedMesh = DefaultMesh.LoadSynchronous();
|
LoadedMesh = DefaultMesh.LoadSynchronous();
|
||||||
if (LoadedMesh)
|
if (LoadedMesh)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#define C_FOLDER TEXT("/Game/CTP/")
|
#define C_FOLDER TEXT("/Game/CTP/")
|
||||||
#define C_INPUT_FOLDER TEXT("/Game/CTP/03_Input/")
|
#define C_INPUT_FOLDER TEXT("/Game/CTP/03_Input/")
|
||||||
#define C_MESH_FOLDER TEXT("Game/CTP/04_Mesh/")
|
#define C_MESH_FOLDER TEXT("/Game/CTP/04_Mesh/")
|
||||||
|
|
||||||
#define PRINT_SCREEN(Text, Color) if(GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, Color, Text);
|
#define PRINT_SCREEN(Text, Color) if(GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, Color, Text);
|
||||||
@@ -44,8 +44,6 @@ protected:
|
|||||||
virtual void OnPossess(APawn* InPawn) override;
|
virtual void OnPossess(APawn* InPawn) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere,BlueprintReadOnly ,Category="Centipede", meta = (AllowPrivateAccess = "true"))
|
|
||||||
TObjectPtr<UCameraComponent> CameraComponent;
|
|
||||||
|
|
||||||
void Move(const FInputActionValue& Value);
|
void Move(const FInputActionValue& Value);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Components/StaticMeshComponent.h"
|
#include "Components/StaticMeshComponent.h"
|
||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "EnhancedInputSubsystems.h"
|
#include "EnhancedInputSubsystems.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
#include "M4_PlayerPawn.generated.h"
|
#include "M4_PlayerPawn.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,5 +48,8 @@ private:
|
|||||||
TSoftObjectPtr<UStaticMesh>(FSoftObjectPath(FString(C_MESH_FOLDER) + MESH_DEFAULT));
|
TSoftObjectPtr<UStaticMesh>(FSoftObjectPath(FString(C_MESH_FOLDER) + MESH_DEFAULT));
|
||||||
|
|
||||||
UStaticMesh* LoadedMesh;
|
UStaticMesh* LoadedMesh;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UCameraComponent* CameraComponent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user