diff --git a/Content/CTP/01_Level/L_Default.umap b/Content/CTP/01_Level/L_Default.umap index b92d96f..5006a92 100644 Binary files a/Content/CTP/01_Level/L_Default.umap and b/Content/CTP/01_Level/L_Default.umap differ diff --git a/Content/CTP/03_Input/IA_Move.uasset b/Content/CTP/03_Input/IA_Move.uasset index ce1bed8..47fa601 100644 Binary files a/Content/CTP/03_Input/IA_Move.uasset and b/Content/CTP/03_Input/IA_Move.uasset differ diff --git a/Content/CTP/03_Input/IMC_Default.uasset b/Content/CTP/03_Input/IMC_Default.uasset index adc6db4..2be9fca 100644 Binary files a/Content/CTP/03_Input/IMC_Default.uasset and b/Content/CTP/03_Input/IMC_Default.uasset differ diff --git a/Source/M4_CPP/private/M4_PlayerController.cpp b/Source/M4_CPP/private/M4_PlayerController.cpp index e7004b6..293298f 100644 --- a/Source/M4_CPP/private/M4_PlayerController.cpp +++ b/Source/M4_CPP/private/M4_PlayerController.cpp @@ -1,6 +1,5 @@ #include "M4_PlayerController.h" #include "EnhancedInputSubsystems.h" -#include "Camera/CameraComponent.h" AM4_PlayerController::AM4_PlayerController() { @@ -9,12 +8,26 @@ AM4_PlayerController::AM4_PlayerController() { DefaultMappingContext = MappingContextRef.Object; } + } void AM4_PlayerController::BeginPlay() { Super::BeginPlay(); + // Spawn a camera actor + FActorSpawnParameters SpawnParameters; + SpawnParameters.Owner = this; + CameraActor = GetWorld()->SpawnActor(SpawnParameters); + CameraActor->SetActorLocation(FVector(-500.f, 0.f, 0.f)); + + CameraActor->GetCameraComponent()->SetProjectionMode(ECameraProjectionMode::Orthographic); + CameraActor->GetCameraComponent()->SetOrthoWidth(1600.f); + CameraActor->GetCameraComponent()->SetWorldLocation(FVector(-500.f, 0.f, 0.f)); + CameraActor->GetCameraComponent()->SetAspectRatio(192.0f/160.0f); + + SetViewTarget(CameraActor); + if (ULocalPlayer* LocalPlayer = GetLocalPlayer()) { if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(LocalPlayer)) diff --git a/Source/M4_CPP/private/M4_PlayerPawn.cpp b/Source/M4_CPP/private/M4_PlayerPawn.cpp index d98f178..8a42c66 100644 --- a/Source/M4_CPP/private/M4_PlayerPawn.cpp +++ b/Source/M4_CPP/private/M4_PlayerPawn.cpp @@ -1,5 +1,6 @@ #include "M4_PlayerPawn.h" #include "EnhancedInputComponent.h" +#include "M4_Gamemode.h" #include "GameFramework/PlayerController.h" #include "Camera/CameraComponent.h" @@ -17,15 +18,8 @@ AM4_PlayerPawn::AM4_PlayerPawn() MeshComponent->SetMobility(EComponentMobility::Movable); MeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); MeshComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName); - MeshComponent->SetRelativeScale3D(FVector(1.0f)); - - 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)); + MeshComponent->SetRelativeScale3D(FVector(1.0f, MeshScale.Y, MeshScale.X)); + static ConstructorHelpers::FObjectFinder DefaultMeshRef(TEXT("/Game/CTP/04_Mesh/SM_Cube.SM_Cube")); if (DefaultMeshRef.Succeeded()) @@ -43,19 +37,22 @@ AM4_PlayerPawn::AM4_PlayerPawn() void AM4_PlayerPawn::BeginPlay() { Super::BeginPlay(); - SetActorLocation(FVector(0.0f, 0.0f, 10.0f)); + SetActorLocation(FVector(0.0f, 0.0f, -400.0f)); } void AM4_PlayerPawn::Tick(float DeltaTime) { Super::Tick(DeltaTime); - if (LastMoveValue != 0) + if (AM4_Gamemode* GM = Cast(GetWorld()->GetAuthGameMode())) { - FVector Loc = GetActorLocation(); - Loc.Y += LastMoveValue * MoveSpeed * DeltaTime; - SetActorLocation(Loc); + FVector NewLocation = GetActorLocation() + FVector( 0.0f, LastMoveValue.Y, LastMoveValue.X) * MoveSpeed * DeltaTime; + NewLocation.Z = FMath::Clamp(NewLocation.Z, GM->Bounds.Min.X, GM->Bounds.Max.X); + NewLocation.Y = FMath::Clamp(NewLocation.Y, GM->Bounds.Min.Y, GM->Bounds.Max.Y); + SetActorLocation(NewLocation); } + + } void AM4_PlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) @@ -72,5 +69,5 @@ void AM4_PlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo void AM4_PlayerPawn::Move(const FInputActionInstance& Instance) { - LastMoveValue = Instance.GetValue().Get(); + LastMoveValue = Instance.GetValue().Get().GetSafeNormal(); } \ No newline at end of file diff --git a/Source/M4_CPP/public/M4_Gamemode.h b/Source/M4_CPP/public/M4_Gamemode.h index 576a910..a81d4fb 100644 --- a/Source/M4_CPP/public/M4_Gamemode.h +++ b/Source/M4_CPP/public/M4_Gamemode.h @@ -20,5 +20,6 @@ public: virtual void BeginPlay() override; - + UPROPERTY(EditAnywhere) + FBox2D Bounds = FBox2D(FVector2D(-400.0f, -750.0f), FVector2D(-200.0f, 750.0f)); }; diff --git a/Source/M4_CPP/public/M4_PlayerController.h b/Source/M4_CPP/public/M4_PlayerController.h index 0ecedd8..b98dc25 100644 --- a/Source/M4_CPP/public/M4_PlayerController.h +++ b/Source/M4_CPP/public/M4_PlayerController.h @@ -3,6 +3,8 @@ #include "CoreMinimal.h" #include "GameFramework/PlayerController.h" #include "InputMappingContext.h" +#include "Camera/CameraComponent.h" +#include "Camera/CameraActor.h" #include "M4_PlayerController.generated.h" UCLASS() @@ -17,4 +19,7 @@ public: protected: UPROPERTY() UInputMappingContext* DefaultMappingContext; + + UPROPERTY() + TObjectPtr CameraActor; }; \ No newline at end of file diff --git a/Source/M4_CPP/public/M4_PlayerPawn.h b/Source/M4_CPP/public/M4_PlayerPawn.h index cbb898d..cd4ff8d 100644 --- a/Source/M4_CPP/public/M4_PlayerPawn.h +++ b/Source/M4_CPP/public/M4_PlayerPawn.h @@ -24,12 +24,10 @@ protected: UPROPERTY(VisibleAnywhere) UStaticMeshComponent* MeshComponent; - UPROPERTY(VisibleAnywhere) - UCameraComponent* CameraComponent; - UPROPERTY() UInputAction* MoveAction; float MoveSpeed = 500.f; - float LastMoveValue = 0; // Pour stockage du mouvement + FVector2D MeshScale = FVector2D(0.6f, 0.5f); + FVector2D LastMoveValue = FVector2D::ZeroVector; }; \ No newline at end of file