(Feat) Add footsteps

This commit is contained in:
2026-08-11 15:23:10 +02:00
parent e8e128457a
commit 176beab9fc
4776 changed files with 18806 additions and 121 deletions
+54 -8
View File
@@ -3,8 +3,9 @@
#include "PickupItem.h"
#include "Components/SphereComponent.h"
#include "Components/BoxComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
#include "InventoryComponent.h"
#include "ItemDataAsset.h"
#include "Net/UnrealNetwork.h"
@@ -26,17 +27,20 @@ APickupItem::APickupItem()
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
SetRootComponent(Mesh);
// Purement decoratif : c'est la sphere qui porte la collision.
// Purement decoratif : c'est la boite qui porte la collision.
Mesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
// Le trace d'interaction passe par le canal Visibility. On ne bloque QUE
// ce canal : le pickup reste traversable par le joueur et les projectiles.
InteractionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("InteractionSphere"));
InteractionSphere->SetupAttachment(Mesh);
InteractionSphere->InitSphereRadius(50.f);
InteractionSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
InteractionSphere->SetCollisionResponseToAllChannels(ECR_Ignore);
InteractionSphere->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
InteractionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("InteractionBox"));
InteractionBox->SetupAttachment(Mesh);
// Valeur de repli seulement : FitInteractionBox l'ecrase des qu'un mesh est
// pose. Elle ne sert qu'aux pickups sans ItemData, et au cas ou
// bAutoFitInteractionBox serait decoche sans qu'on regle la boite.
InteractionBox->SetBoxExtent(FVector(25.f));
InteractionBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
InteractionBox->SetCollisionResponseToAllChannels(ECR_Ignore);
InteractionBox->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
}
void APickupItem::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
@@ -61,6 +65,48 @@ void APickupItem::ApplyItemVisuals()
{
ItemData->ApplyWorldVisualsTo(Mesh);
}
// Hors du if, et apres lui : la boite doit suivre le mesh REELLEMENT pose,
// que celui-ci vienne de l'ItemData ou qu'il ait ete impose a la main.
if (bAutoFitInteractionBox)
{
FitInteractionBox();
}
}
void APickupItem::FitInteractionBox()
{
const UStaticMesh* CurrentMesh = Mesh->GetStaticMesh();
if (!CurrentMesh)
{
// Pickup non configure, ou client dont l'ItemData n'est pas encore arrive :
// on garde la boite du Blueprint plutot que de l'ecraser par un volume nul.
// OnRep_ItemData repassera ici quand la donnee sera la.
return;
}
// La bounding box de l'ASSET, jamais Mesh->Bounds : ces dernieres sont en
// espace monde et deja multipliees par l'echelle de l'acteur. Or SetBoxExtent
// recoit une extension LOCALE que le moteur remultiplie a son tour -- une
// instance posee a l'echelle 2 aurait une boite quatre fois trop grande.
const FBox LocalBounds = CurrentMesh->GetBoundingBox();
// Le pivot d'un mesh d'asset pack tombe rarement au centre de sa geometrie :
// il est presque toujours au sol, parfois franchement decale. Une boite
// laissee a l'origine deborderait d'un cote et laisserait l'autre invisable.
InteractionBox->SetRelativeLocation(LocalBounds.GetCenter());
// ComponentMax et non un Max sur la norme : le plancher s'applique axe par
// axe, sinon relever l'epaisseur d'une branche rallongerait aussi la boite
// dans le sens ou elle etait deja bien assez grande.
const FVector Fitted = LocalBounds.GetExtent() + FVector(InteractionBoxPadding);
// bUpdateOverlaps a false : cette boite ne bloque que le canal Visibility et
// ne genere aucun evenement d'overlap. Le defaut (true) declencherait une
// requete physique par pickup a chaque spawn, pour rien.
InteractionBox->SetBoxExtent(
Fitted.ComponentMax(FVector(MinInteractionExtent)),
/*bUpdateOverlaps=*/ false);
}
void APickupItem::OnRep_ItemData()