gpt4 book ai didi

c++ - USphereComponent 和 Overlap 事件

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:58 25 4
gpt4 key购买 nike

我似乎误解了如何在我的组件上实现重叠事件。我创建了一个 USphereComponent 来跟随我的角色。它旨在在玩家触及范围内的其他附近 Actor 上触发重叠事件:

AScrollsCharacter::AScrollsCharacter()
{
...Redacted irellevant code...

//Create activate trigger radius
USphereComponent* activateRadius = CreateDefaultSubobject<USphereComponent>(TEXT("Activate Radius"));
activateRadius->InitSphereRadius(ACTIVATE_RADIUS);
activateRadius->bGenerateOverlapEvents = true;
activateRadius->SetupAttachment(RootComponent);
activateRadius->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
activateRadius->OnComponentBeginOverlap.AddDynamic(this, &AScrollsCharacter::OnOverlapActivateSphere);
activateRadius->bHiddenInGame = false;
}

void AScrollsCharacter::OnOverlapActivateSphere(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("We got a collision."));
}

球体组件没有错误地附加,并且半径以正确的大小绘制在屏幕上。但是,当我将半径引向游戏中的其他参与者并使它们重叠时,事件似乎并未触发。

所有涉及的参与者都将“生成重叠事件”标志设置为 true。

有人可以帮助我了解我在此设置中缺少的内容吗?

注意:球体组件的调试边界在编辑器中为橙色,但在游戏运行时变为红色。这种颜色变化有意义吗?

最佳答案

确保涉及的其他参与者也启用了碰撞,并确保它们确实具有碰撞组件。例如,如果其他 Actor 有骨架网格组件,则该网格需要有物理 Assets ,否则它不会发生任何碰撞!您还可以向其他 Actor 添加碰撞球体/盒子/胶囊,并确保在其上启用碰撞!

关于c++ - USphereComponent 和 Overlap 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39502868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com