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; };