RPG22.处理武器碰撞
一般情况下,在非攻击状态武器时不会有碰撞的。则要在进行攻击的时候进行碰撞检测,所以使用动画通知进行开启与关闭碰撞检测。
1.新建一个接口
然后重写一个虚函数
public:virtual UPawnCombatComponent* GetPawnCombatComponent() const = 0;
新建一个空文件WarriorEnumTypes用于存储枚举
#pragma onceUENUM()
enum class EXMBWarriorConfirmType : uint8
{Yes,No
};UENUM()
enum class EWarriorValidType : uint8
{Valid,Invalid};
2.然后在CharacterBase内,继承接口以及覆写函数
public:
//Begin IPawnCombatInterface Interfacevirtual UPawnCombatComponent* GetPawnCombatComponent() const override;//End IPawnCombatInterface Interface
UPawnCombatComponent* ACharacterBase::GetPawnCombatComponent() const
{return nullptr;
}
进入XMBCharacter和EnemyCharacterBase内做同样的事
//Begin IPawnCombatInterface Interfacevirtual UPawnCombatComponent* GetPawnCombatComponent() const override;//End IPawnCombatInterface Interface
UPawnCombatComponent* AXMBCharacter::GetPawnCombatComponent() const
{return XMBCombatComponent;
}
//Begin IPawnCombatInterface Interfacevirtual UPawnCombatComponent* GetPawnCombatComponent() const override;//End IPawnCombatInterface Interface
UPawnCombatComponent* AEnemyCharacterBase::GetPawnCombatComponent() const
{return EnemyCombatComponent;
}
3.进入Library内,
static UPawnCombatComponent* NativeGetPawnCombatComponentFromActor(AActor* InActor);UFUNCTION(BlueprintCallable, Category = "XMBWorrior|FunctionLibrary", meta = (DisplayName = "Get Pawn Combat Component From Actor", ExpandEnumAsExecs = "OutValidType"))static UPawnCombatComponent* BP_GetPawnCombatComponentFromActor(AActor* InActor, EWarriorValidType& OutValidType);
UPawnCombatComponent*UXMBWarriorFunctionLibrary::NativeGetPawnCombatComponentFromActor(AActor* InActor)
{
check(InActor);
if (IPawnCombatInterface* PawnCombatInterface = Cast<IPawnCombatInterface>(InActor)){return PawnCombatInterface->GetPawnCombatComponent();}
return nullptr;
}UPawnCombatComponent* UXMBWarriorFunctionLibrary::BP_GetPawnCombatComponentFromActor(AActor* InActor,EWarriorValidType& OutValidType)
{UPawnCombatComponent* CombatComponent = NativeGetPawnCombatComponentFromActor(InActor);
OutValidType = CombatComponent ? EWarriorValidType::Valid : EWarriorValidType::Invalid;
return CombatComponent;
}
4。启动项目,创建动画状态通知
在Begin内连图