作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我似乎误解了如何在我的组件上实现重叠事件。我创建了一个 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/
我似乎误解了如何在我的组件上实现重叠事件。我创建了一个 USphereComponent 来跟随我的角色。它旨在在玩家触及范围内的其他附近 Actor 上触发重叠事件: AScrollsCharact
我是一名优秀的程序员,十分优秀!