虚幻引擎5几何集合获取所有骨骼并施加力

问题描述 投票:0回答:1

使用虚幻引擎 5.4.3,我实现了自定义

AGeometryCollectionActor
,我想在勾选时对该集合的各个骨骼施加力。以下是我正在尝试做的事情的玩具版本。我可以通过
GetAllPhysicsObjects
读取所有骨骼的位置,但似乎无法将“骨骼名称”传递给
GeometryCollectionComponent->AddForce
方法。

自定义几何集合.cpp

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);
    }
}
c++ game-physics unreal-engine5 physics-engine
1个回答
1
投票

解决方法在这里

自定义几何集合.cpp

#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"
添加到 .Build.cs 文件中的依赖模块名称中。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.