#UE4 C++ 碰撞体
.h
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class USphereComponent* HitBoxBase;
private:
UFUNCTION()
void HitBoxCollideBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void HitBoxCollideEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
.c
HitBoxBase = CreateDefaultSubobject<USphereComponent>(TEXT("HitBox"));
HitBoxBase->SetupAttachment(RootComponent);//附加到根
HitBoxBase->SetSphereRadius(1000.f); // 声明碰撞体半径
//
//Bind
HitBoxBase->OnComponentBeginOverlap.AddDynamic(this, &AAICharacterBase::HitBoxCollideBegin);//进入碰撞体事件
HitBoxBase->OnComponentEndOverlap.AddDynamic(this, &AAICharacterBase::HitBoxCollideEnd);//退出碰撞体事件