【问题标题】:Adding Ammo Count to Game.将弹药计数添加到游戏中。
【发布时间】:2019-01-13 02:36:30
【问题描述】:

我已经尝试添加此功能已经有一段时间了。不过,我好像忽略了什么。

所以我想添加一个弹药数量,一个类似于 Quake 或 Doom 的单个弹药数量。弹药拾取器分布在整个地图上。枪最多可以发射 10 次然后停止,但是当我尝试通过与弹药拾取器重叠来重新加载时,静态网格没有响应。静态 mash 父级是一个蓝图(actor),它的父类是 ammocrate.cpp(下图),它也是一个actor。这是我到目前为止所做的。

AmmoCrate.cpp

 AAmmoCrate::AAmmoCrate()
    {
        PrimaryActorTick.bCanEverTick = true;

        Count = 10;
        SphereRadius = 100.0f;

        TouchSphere = CreateDefaultSubobject<USphereComponent>(TEXT("TouchSphereComponent"));
        TouchSphere->InitSphereRadius(SphereRadius);
        TouchSphere->SetCollisionProfileName("Trigger");
        RootComponent = TouchSphere;

        StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
        StaticMesh->SetupAttachment(RootComponent);

        TouchSphere->OnComponentBeginOverlap.AddDynamic(this, &AAmmoCrate::OnOverlapBegin);
    }

    void AAmmoCrate::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
    {
        AFirstPersonCharacter *FPCharacter = Cast<AFirstPersonCharacter>(OtherActor);
        AMannequin* TPCharacter = Cast<AMannequin>(OtherActor);
        AGun *Gun = Cast<AGun>(OtherActor);

if (TPCharacter)
{
    Gun->AmmoPool = Gun->AmmoPool + Count;

    this->Destroy();
}

之后我创建了一个类似于 OnFire() 函数的 OnReload() 函数,我从第一人称角色中调用它。

FirstPersonCharacter.cpp

void AFirstPersonCharacter::OnReload()
{
    Gun->OnReload();
}

我在 OnReload 函数上设置了 UE_LOG 调用,它甚至没有注销弹药箱已经重叠,我在这里缺少什么?

【问题讨论】:

  • 你的重叠体积比你的网格大吗?

标签: c++ unreal-engine4 unreal-development-kit


【解决方案1】:

在 FPS 角色胶囊和弹药箱碰撞器的碰撞设置中,GenerateOverlapEvents 是否检查为 true? 两个碰撞器是否都在可以生成重叠事件的正确通道中?

【讨论】:

    猜你喜欢
    • 2017-08-07
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2019-09-09
    相关资源
    最近更新 更多