当前位置: 首页 > news >正文

UE5多人MOBA+GAS 19、创建升龙技能,以及带力的被动,为升龙技能添加冷却和消耗

文章目录

  • 创建升龙拳的Tag以及受力被动的Tag
  • 创建升龙技能
    • 将升龙技能添加到角色中
    • 创建一个击飞被动,供升龙激活技能
  • 为技能添加冷却以及消耗


创建升龙拳的Tag以及受力被动的Tag

给这个技能添加标签

CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Uppercut_Launch)
CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Passive_Launch_Activate)
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Uppercut_Launch, "Ability.Uppercut.Launch", "升龙拳攻击")
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Passive_Launch_Activate, "Ability.Passive.Launch.Activate", "击飞被动技能激活")

CGameplayAbility中添加绘制Debug的布尔变量(暂时对我没的没什么用)

	UFUNCTION()FORCEINLINE bool ShouldDrawDebug() const { return bShouldDrawDebug; }
private:UPROPERTY(EditDefaultsOnly, Category = "Debug")bool bShouldDrawDebug = false;

创建升龙技能

添加上勾拳(升龙拳)技能,命名为UpperCut
在这里插入图片描述

// 幻雨喜欢小猫咪#pragma once#include "CoreMinimal.h"
#include "GAS/Core/CGameplayAbility.h"
#include "UpperCut.generated.h"/*** */
UCLASS()
class CRUNCH_API UUpperCut : public UCGameplayAbility
{GENERATED_BODY()
public:	// 激活技能时调用virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) override;
private:// 上勾拳动画MontageUPROPERTY(EditDefaultsOnly, Category = "Animation")TObjectPtr<UAnimMontage> UpperCutMontage;// 启动击飞效果UFUNCTION()void StartLaunching(FGameplayEventData EventData);
};
// 幻雨喜欢小猫咪#include "UpperCut.h"#include "Abilities/Tasks/AbilityTask_PlayMontageAndWait.h"void UUpperCut::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{if (!K2_CommitAbility()){K2_EndAbility();return;}// 服务器执行if (HasAuthorityOrPredictionKey(ActorInfo, &ActivationInfo)){UAbilityTask_PlayMontageAndWait* PlayUpperCutMontageTask = UAbilityTask_PlayMontageAndWait::CreatePlayMontageAndWaitProxy(this, NAME_None, UpperCutMontage);PlayUpperCutMontageTask->OnBlendOut.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnCancelled.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnCompleted.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->OnInterrupted.AddDynamic(this, &UUpperCut::K2_EndAbility);PlayUpperCutMontageTask->ReadyForActivation();UAbilityTask_WaitGameplayEvent* WaitLaunchEventTask = UAbilityTask_WaitGameplayEvent::WaitGameplayEvent(this, TGameplayTags::Ability_Uppercut_Launch);WaitLaunchEventTask->EventReceived.AddDynamic(this, &UUpperCut::StartLaunching);WaitLaunchEventTask->ReadyForActivation();}
}void UUpperCut::StartLaunching(FGameplayEventData EventData)
{if (K2_HasAuthority()){// 获取命中目标的数量int32 HitResultCount = UAbilitySystemBlueprintLibrary::GetDataCountFromTargetData(EventData.TargetData);for (int32 i = 0; i < HitResultCount; ++i){// 获取每个命中的HitResultFHitResult HitResult = UAbilitySystemBlueprintLibrary::GetHitResultFromTargetData(EventData.TargetData, i);UE_LOG(LogTemp, Warning, TEXT("HitActorName:  %s"), *HitResult.GetActor()->GetName())}}
}

将升龙技能添加到角色中

蓝图继承并创建
在这里插入图片描述
在这里插入图片描述
直接复制基础攻击增加一个技能一
在这里插入图片描述
添加到映射中
在这里插入图片描述

将技能添加到角色中
在这里插入图片描述

创建一个击飞被动,供升龙激活技能

添加一个新的类GAP_Launched,作为击飞的被动技能
在这里插入图片描述

// 幻雨喜欢小猫咪#pragma once#include "CoreMinimal.h"
#include "GAS/Core/CGameplayAbility.h"
#include "GAP_Launched.generated.h"/*** 被击飞能力类* 用于处理角色被击飞时的特殊能力逻辑*/
UCLASS()
class UGAP_Launched : public UCGameplayAbility
{GENERATED_BODY()
public:// 构造函数UGAP_Launched();// 激活能力时调用virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData) override;// 获取击飞激活事件Tagstatic FGameplayTag GetLaunchedAbilityActivationTag();
};
// 幻雨喜欢小猫咪#include "GAP_Launched.h"#include "GAS/Core/TGameplayTags.h"UGAP_Launched::UGAP_Launched()
{// 设置网络执行策略为仅在服务器端执行NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::ServerOnly;// 创建一个新的触发数据对象FAbilityTriggerData TriggerData;// 设置触发数据的触发源为游戏事件TriggerData.TriggerSource = EGameplayAbilityTriggerSource::GameplayEvent;// 设置触发数据的触发标签为击飞被动技能激活标签TriggerData.TriggerTag = TGameplayTags::Ability_Passive_Launch_Activate;// 将创建好的触发数据添加到能力触发器列表中AbilityTriggers.Add(TriggerData);
}void UGAP_Launched::ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo,const FGameplayAbilityActivationInfo ActivationInfo, const FGameplayEventData* TriggerEventData)
{if (!K2_CommitAbility()){K2_EndAbility();return;}if (K2_HasAuthority()){// 推自己PushSelf(TriggerEventData->TargetData.Get(0)->GetHitResult()->ImpactNormal);K2_EndAbility();}
}FGameplayTag UGAP_Launched::GetLaunchedAbilityActivationTag()
{return TGameplayTags::Ability_Passive_Launch_Activate;
}

CGameplayAbility中添加推动自身的力

	// 推动自己(如击退/击飞)void PushSelf(const FVector& PushVel);void PushTarget(AActor* Target, const FVector& PushVel);// 获取拥有者角色指针ACharacter* GetOwningAvatarCharacter();
private:// 缓存的拥有者角色指针UPROPERTY()TObjectPtr<ACharacter> AvatarCharacter;
void UCGameplayAbility::PushSelf(const FVector& PushVel)
{ACharacter* OwningAvatarCharacter = GetOwningAvatarCharacter();if (OwningAvatarCharacter){OwningAvatarCharacter->LaunchCharacter(PushVel, true, true);}
}void UCGameplayAbility::PushTarget(AActor* Target, const FVector& PushVel)
{// 目标为空则返回if (!Target) return;FGameplayEventData EventData;// 创建单目标命中数据对象FGameplayAbilityTargetData_SingleTargetHit* HitData = new FGameplayAbilityTargetData_SingleTargetHit;// 配置命中结果参数FHitResult HitResult;HitResult.ImpactNormal = PushVel; // 设置冲击方向为力的方向HitData->HitResult = HitResult;EventData.TargetData.Add(HitData);// 用标签激活技能UAbilitySystemBlueprintLibrary::SendGameplayEventToActor(Target, UGAP_Launched::GetLaunchedAbilityActivationTag(), EventData);
}ACharacter* UCGameplayAbility::GetOwningAvatarCharacter()
{if (!AvatarCharacter){AvatarCharacter = Cast<ACharacter>(GetAvatarActorFromActorInfo());}return AvatarCharacter;
}

回到升龙技能中,实现力技能的添加,再添加一个伤害效果

    // 上勾拳击飞阶段的伤害效果UPROPERTY(EditDefaultsOnly, Category = "Launch")TSubclassOf<UGameplayEffect> LaunchDamageEffect;// 上勾拳击飞速度UPROPERTY(EditDefaultsOnly, Category = "Launch", meta = (DisplayName = "击飞力的大小"))float UpperCutLaunchSpeed = 1000.f;
void UUpperCut::StartLaunching(FGameplayEventData EventData)
{if (K2_HasAuthority()){// 获取命中目标的数量int32 HitResultCount = UAbilitySystemBlueprintLibrary::GetDataCountFromTargetData(EventData.TargetData);// 推动自己向上PushTarget(GetAvatarActorFromActorInfo(), FVector::UpVector * UpperCutLaunchSpeed);for (int32 i = 0; i < HitResultCount; ++i){// 获取每个命中的HitResultFHitResult HitResult = UAbilitySystemBlueprintLibrary::GetHitResultFromTargetData(EventData.TargetData, i);PushTarget(HitResult.GetActor(), FVector::UpVector * UpperCutLaunchSpeed);ApplyGameplayEffectToHitResultActor(HitResult, LaunchDamageEffect, GetAbilityLevel(CurrentSpecHandle, CurrentActorInfo));}}
}

为角色添加基础技能,因为是通过tag触发的,所以不用管输入
在这里插入图片描述
创建一个GE
在这里插入图片描述
在这里插入图片描述
然后一个升龙拳双方都起飞了
在这里插入图片描述

为技能添加冷却以及消耗

创建一个tag表示升龙的冷却,在冷却标签存在的时间内是无法再次使用此技能。

CRUNCH_API UE_DECLARE_GAMEPLAY_TAG_EXTERN(Ability_Uppercut_Cooldown)
UE_DEFINE_GAMEPLAY_TAG_COMMENT(Ability_Uppercut_Cooldown, "Ability.Uppercut.Cooldown", "升龙拳技能冷却")

创建一个GE来设置拥有持续时间,在GA的冷却中添加该GE
在这里插入图片描述
将CD添加到GA中
在这里插入图片描述
创建一个GE作为开销
在这里插入图片描述
在这里插入图片描述
用技能就会耗蓝了
在这里插入图片描述

http://www.dtcms.com/a/275969.html

相关文章:

  • 3. java 堆和 JVM 内存结构
  • YOLOv8
  • pytables模块安装
  • 【TOOL】ubuntu升级cmake版本
  • 单细胞分析教程 | (二)标准化、特征选择、降为、聚类及可视化
  • STM32用PWM驱动步进电机
  • 快捷跑通ultralytics下的yolo系列
  • 算法第三十一天:贪心算法part05(第八章)
  • 回溯算法-数据结构与算法
  • Pythone第二次作业
  • brpc 介绍与安装
  • Redis过期策略与内存淘汰机制面试笔记
  • 数据库连接池及其核心特点
  • AI编程下的需求规格文档的问题及新规范
  • ADSP-1802这颗ADI的最新DSP应该怎么做开发(一)
  • 【Redis实战】Widnows本地模拟Redis集群的2种方法
  • Syntax Error: TypeError: Cannot set properties of undefined (setting ‘parent‘)
  • Unity URP + XR 自定义 Skybox 在真机变黑问题全解析与解决方案(支持 Pico、Quest 等一体机)
  • Cookie、Session、Token 有什么区别?
  • Spring Boot 中使用 Lombok 进行依赖注入的示例
  • 【离线数仓项目】——电商域DWD层开发实战
  • 【C++ STL 库】解析stack、queue、priority_queue类
  • 中文多智能体金融交易决策框架-TradingAgents-CN
  • 本地安装ClaudeCode全攻略
  • 【Python】多线程详解:从基础概念到实战应用
  • 免费尝试claude code的安利,截至今天可用(7/12)
  • openGauss数据库管理实战指南——基本常用操作总结
  • AI:机器人未来的形态是什么?
  • Cisco ACI 生成Postman CSV 脚本场景
  • 死锁的避免