使用虚幻引擎 5.4.3,我实现了自定义
AGeometryCollectionActor
,我想在勾选时对该集合的各个骨骼施加力。以下是我正在尝试做的事情的玩具版本。我可以通过 GetAllPhysicsObjects
读取所有骨骼的位置,但似乎无法将“骨骼名称”传递给 GeometryCollectionComponent->AddForce
方法。
void ACustomGeometryCollection::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
FVector TestForce = FVector(0, 0, 100);
for (Chaos::FPhysicsObject* Obj : GeometryCollectionComponent->GetAllPhysicsObjects())
{
// this has no effect
GeometryCollectionComponent->AddForce(TestForce, Obj->GetBodyName(), true);
}
}
解决方法在这里
#include "GeometryCollection/GeometryCollectionComponent.h"
#include "Runtime/Experimental/Chaos/Private/Chaos/PhysicsObjectInternal.h"
void ACustomGeometryCollection::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
FVector TestForce = FVector(0, 0, 100);
for (int32 i = 0; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
{
GeometryCollectionComponent->ApplyLinearVelocity(i, TestForce);
}
}
此外,还需要将
"GeometryCollectionEngine"
添加到