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:
2025-10-15 16:52:24 +02:00
parent 55a9234871
commit f1cbe8c8c3
5 changed files with 16 additions and 29 deletions

View File

@@ -6,28 +6,14 @@
AM4_PlayerController::AM4_PlayerController()
{
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComponent->ProjectionMode = ECameraProjectionMode::Orthographic;
CameraComponent->OrthoWidth = 2048.0f;
CameraComponent->SetAspectRatio(160.0f/192.0f);
// attach the camera to the controller's root component
CameraComponent->SetupAttachment(GetRootComponent());
PrimaryActorTick.bCanEverTick = false;
PrimaryActorTick.bStartWithTickEnabled = false;
}
void AM4_PlayerController::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())
{
@@ -105,13 +91,4 @@ void AM4_PlayerController::Move(const FInputActionValue& Value)
void AM4_PlayerController::OnPossess(APawn* 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));
}
}

View File

@@ -18,6 +18,14 @@ AM4_PlayerPawn::AM4_PlayerPawn()
MeshComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f));
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();
if (LoadedMesh)
{

View File

@@ -3,6 +3,6 @@
#define C_FOLDER TEXT("/Game/CTP/")
#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);

View File

@@ -44,8 +44,6 @@ protected:
virtual void OnPossess(APawn* InPawn) override;
private:
UPROPERTY(VisibleAnywhere,BlueprintReadOnly ,Category="Centipede", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UCameraComponent> CameraComponent;
void Move(const FInputActionValue& Value);

View File

@@ -16,6 +16,7 @@
#include "Components/StaticMeshComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Camera/CameraComponent.h"
#include "M4_PlayerPawn.generated.h"
/**
@@ -48,4 +49,7 @@ private:
UStaticMesh* LoadedMesh;
UPROPERTY(VisibleAnywhere)
UCameraComponent* CameraComponent;
};