From 7e3424d0f64dd7a588690030be13cb5e0ad3452e Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Fri, 17 Oct 2025 16:51:24 +0200 Subject: [PATCH] Minor - Modifie la trajectoire de la centipede - V2.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajuste le déplacement de la centipede en modifiant le calcul de sa trajectoire. La centipede se déplace désormais horizontalement, ce qui améliore sa visibilité. --- Source/M4_CPP/private/M4_CentipedeBody.cpp | 1 - .../M4_CPP/private/M4_CentipedeController.cpp | 21 +++++++------------ Source/M4_CPP/private/M4_Gamemode.cpp | 3 +-- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Source/M4_CPP/private/M4_CentipedeBody.cpp b/Source/M4_CPP/private/M4_CentipedeBody.cpp index 3643cfd..df0bdc3 100644 --- a/Source/M4_CPP/private/M4_CentipedeBody.cpp +++ b/Source/M4_CPP/private/M4_CentipedeBody.cpp @@ -10,7 +10,6 @@ AM4_CentipedeBody::AM4_CentipedeBody() GetStaticMeshComponent()->SetStaticMesh(MeshRef.Object); } - // Charger les matériaux par défaut (ajustez les chemins selon vos assets) static ConstructorHelpers::FObjectFinder HeadMatRef(TEXT("/Game/CTP/05_Material/MI_Head.MI_Head")); if (HeadMatRef.Succeeded()) { diff --git a/Source/M4_CPP/private/M4_CentipedeController.cpp b/Source/M4_CPP/private/M4_CentipedeController.cpp index 2c965cf..96b237f 100644 --- a/Source/M4_CPP/private/M4_CentipedeController.cpp +++ b/Source/M4_CPP/private/M4_CentipedeController.cpp @@ -36,7 +36,7 @@ void UM4_CentipedeController::StartCentipede(FVector SpawnLocation) for (int32 i = 0; i < BodyCount; ++i) { - FVector SegmentLocation = SpawnLocation - FVector(0.f, 0.f, i * CellSize); + FVector SegmentLocation = SpawnLocation - FVector(0.f, i * CellSize, 0.f); AM4_CentipedeBody* Body = GetWorld()->SpawnActor( AM4_CentipedeBody::StaticClass(), @@ -57,8 +57,7 @@ void UM4_CentipedeController::StartCentipede(FVector SpawnLocation) Body->SetAsHead(i == 0); } } - - // Initialiser l'historique + SegmentHistory.SetNum(BodyCount); for (int32 i = 0; i < BodyCount; ++i) { @@ -66,7 +65,6 @@ void UM4_CentipedeController::StartCentipede(FVector SpawnLocation) { FVector InitialPos = BodySegments[i]->GetActorLocation(); - // Remplir avec position initiale int32 InitialHistorySize = SegmentSpacing * (i + 1) + MaxHistorySize; for (int32 j = 0; j < InitialHistorySize; ++j) { @@ -138,8 +136,7 @@ void UM4_CentipedeController::Tick(float DeltaTime) Super::Tick(DeltaTime); if (BodySegments.Num() == 0) return; - - // Déplacer la tête + AM4_CentipedeBody* Head = BodySegments[0]; if (Head && Head->bIsHead) { @@ -161,22 +158,19 @@ void UM4_CentipedeController::Tick(float DeltaTime) FVector NewPos = CurrentPos + FVector(0.f, SegmentDirection.Y * CentipedeSpeed * DeltaTime, 0.f); Head->SetActorLocation(NewPos); } - - // Enregistrer position de la tête + SegmentHistory[0].Add(Head->GetActorLocation()); if (SegmentHistory[0].Num() > MaxHistorySize) { SegmentHistory[0].RemoveAt(0); } } - - // Faire suivre les autres segments + for (int32 i = 1; i < BodySegments.Num(); ++i) { AM4_CentipedeBody* Segment = BodySegments[i]; if (!Segment) continue; - - // Récupérer position dans l'historique du segment précédent + int32 PrevIndex = i - 1; int32 HistoryLookback = SegmentSpacing; @@ -186,8 +180,7 @@ void UM4_CentipedeController::Tick(float DeltaTime) FVector TargetPos = SegmentHistory[PrevIndex][HistoryIndex]; Segment->SetActorLocation(TargetPos); - - // Enregistrer position actuelle + SegmentHistory[i].Add(Segment->GetActorLocation()); if (SegmentHistory[i].Num() > MaxHistorySize) { diff --git a/Source/M4_CPP/private/M4_Gamemode.cpp b/Source/M4_CPP/private/M4_Gamemode.cpp index 304dfeb..2d97557 100644 --- a/Source/M4_CPP/private/M4_Gamemode.cpp +++ b/Source/M4_CPP/private/M4_Gamemode.cpp @@ -85,8 +85,7 @@ void AM4_Gamemode::BeginPlay() ); } } - - // Spawn centipede controller + PRINT_SCREEN(TEXT("Spawning Centipede Controller"), FColor::Green); FVector CentipedeSpawnLocation = FVector(