From f1cbe8c8c31cf52bd714052210adce6fee2c3e24 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Wed, 15 Oct 2025 16:52:24 +0200 Subject: [PATCH] =?UTF-8?q?Minor=20-=20D=C3=A9place=20la=20cam=C3=A9ra=20v?= =?UTF-8?q?ers=20le=20PlayerPawn=20-=20V01.04.00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Source/M4_CPP/private/M4_PlayerController.cpp | 29 ++----------------- Source/M4_CPP/private/M4_PlayerPawn.cpp | 8 +++++ Source/M4_CPP/public/M4_CTP_Macros.h | 2 +- Source/M4_CPP/public/M4_PlayerController.h | 2 -- Source/M4_CPP/public/M4_PlayerPawn.h | 4 +++ 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/Source/M4_CPP/private/M4_PlayerController.cpp b/Source/M4_CPP/private/M4_PlayerController.cpp index ec25868..60b7de5 100644 --- a/Source/M4_CPP/private/M4_PlayerController.cpp +++ b/Source/M4_CPP/private/M4_PlayerController.cpp @@ -6,28 +6,14 @@ AM4_PlayerController::AM4_PlayerController() { - CameraComponent = CreateDefaultSubobject(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)); - } } \ No newline at end of file diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index 6cc2111..f3722ff 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -18,6 +18,14 @@ AM4_PlayerPawn::AM4_PlayerPawn() MeshComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f)); MeshComponent->SetupAttachment(RootComponent); + CameraComponent = CreateDefaultSubobject(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) { diff --git a/Source/M4_CPP/public/M4_CTP_Macros.h b/Source/M4_CPP/public/M4_CTP_Macros.h index 9760632..68a03f6 100644 --- a/Source/M4_CPP/public/M4_CTP_Macros.h +++ b/Source/M4_CPP/public/M4_CTP_Macros.h @@ -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); \ No newline at end of file diff --git a/Source/M4_CPP/public/M4_PlayerController.h b/Source/M4_CPP/public/M4_PlayerController.h index 37aaa6c..3063c4e 100644 --- a/Source/M4_CPP/public/M4_PlayerController.h +++ b/Source/M4_CPP/public/M4_PlayerController.h @@ -44,8 +44,6 @@ protected: virtual void OnPossess(APawn* InPawn) override; private: - UPROPERTY(VisibleAnywhere,BlueprintReadOnly ,Category="Centipede", meta = (AllowPrivateAccess = "true")) - TObjectPtr CameraComponent; void Move(const FInputActionValue& Value); diff --git a/Source/M4_CPP/public/M4_PlayerPawn.h b/Source/M4_CPP/public/M4_PlayerPawn.h index 679ec92..b2b34a9 100644 --- a/Source/M4_CPP/public/M4_PlayerPawn.h +++ b/Source/M4_CPP/public/M4_PlayerPawn.h @@ -16,6 +16,7 @@ #include "Components/StaticMeshComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "Camera/CameraComponent.h" #include "M4_PlayerPawn.generated.h" /** @@ -47,5 +48,8 @@ private: TSoftObjectPtr(FSoftObjectPath(FString(C_MESH_FOLDER) + MESH_DEFAULT)); UStaticMesh* LoadedMesh; + + UPROPERTY(VisibleAnywhere) + UCameraComponent* CameraComponent; };