Files
M4_CPP/Source/M4_CPP/private/M4_CentipedeBody.cpp
CatChow0 987856ca09 Major - Implémente le contrôleur de mille-pattes - V2.0.0
This commit introduces a centipede controller subsystem, managing centipede spawning, movement, and segment behavior.

It adds centipede body materials, movement logic, collision detection, and head assignment.
The controller handles segment following, direction changes at boundaries, and dynamic head updates upon segment destruction.
2025-10-17 16:32:27 +02:00

52 lines
1.5 KiB
C++

#include "M4_CentipedeBody.h"
AM4_CentipedeBody::AM4_CentipedeBody()
{
PrimaryActorTick.bCanEverTick = false;
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshRef(TEXT("/Game/CTP/04_Mesh/SM_Cube.SM_Cube"));
if (MeshRef.Succeeded())
{
GetStaticMeshComponent()->SetStaticMesh(MeshRef.Object);
}
// Charger les matériaux par défaut (ajustez les chemins selon vos assets)
static ConstructorHelpers::FObjectFinder<UMaterialInterface> HeadMatRef(TEXT("/Game/CTP/05_Material/MI_Head.MI_Head"));
if (HeadMatRef.Succeeded())
{
HeadMaterial = HeadMatRef.Object;
}
static ConstructorHelpers::FObjectFinder<UMaterialInterface> BodyMatRef(TEXT("/Game/CTP/05_Material/MI_Body.MI_Body"));
if (BodyMatRef.Succeeded())
{
BodyMaterial = BodyMatRef.Object;
}
GetStaticMeshComponent()->SetRelativeScale3D(FVector(1.f, 0.4f, 0.4f));
GetStaticMeshComponent()->SetMobility(EComponentMobility::Movable);
GetStaticMeshComponent()->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
GetStaticMeshComponent()->SetGenerateOverlapEvents(true);
GetStaticMeshComponent()->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
GetStaticMeshComponent()->SetCollisionProfileName(TEXT("OverlapAll"));
}
void AM4_CentipedeBody::SetAsHead(bool bHead)
{
bIsHead = bHead;
if (bIsHead)
{
if (HeadMaterial)
{
GetStaticMeshComponent()->SetMaterial(0, HeadMaterial);
}
}
else
{
if (BodyMaterial)
{
GetStaticMeshComponent()->SetMaterial(0, BodyMaterial);
}
}
}