尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

22,攻击检测改为C++

22,攻击检测改为C++
📅 发布时间:2026/7/10 12:00:41

回到动画源中

进行攻击检测的动画通知改写

这里用到了蓝图接口

把蓝图接口改为C++
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “UObject/Interface.h”
#include “Combat.generated.h”

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UCombat : public UInterface
{
GENERATED_BODY()
};

/**
*
*/
class ROUGHLIKE1_API ICombat
{
GENERATED_BODY()

// Add interface functions to this class. This is the class that will be inherited to implement this interface.

public:
//攻击重置
UFUNCTION(BlueprintNativeEvent, Category = “Combat”)
void INT_ResetAtk();
virtual void INT_ResetAtk_Implementation() = 0;

//攻击检测 UFUNCTION(BlueprintNativeEvent, Category = "Combat") void INT_AttackDetection(FVector boxPosition, FVector boxExtension); virtual void INT_AttackDetection_Implementation(FVector boxPosition, FVector boxExtension) = 0;

};
再写动画通知类
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “Notifies/PaperZDAnimNotify.h”
#include “ANZ_Attack.generated.h”

/**
*
*/
UCLASS()
class ROUGHLIKE1_API UANZ_Attack : public UPaperZDAnimNotify
{
GENERATED_BODY()

public:
UANZ_Attack();
//攻击盒大小
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Attack”)
FVector BoxExtent;
//攻击位置的Socket名称
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “Attack”)
FName socketName;

protected:
//重写动画通知的触发事件
virtual void OnReceiveNotify_Implementation(UPaperZDAnimInstance* OwningInstance) const override;

};
// Fill out your copyright notice in the Description page of Project Settings.

#include “AnimNotify/ANZ_Attack.h”
#include <Interface/Combat.h>
#include <PaperZDAnimInstance.h>
#include <MyPaperZDCharacter.h>

UANZ_Attack::UANZ_Attack()
{
BoxExtent = FVector(100.0f, 50.0f, 50.0f);
socketName = TEXT(“Socket_ATK”);
}

void UANZ_Attack::OnReceiveNotify_Implementation(UPaperZDAnimInstance* OwningInstance) const
{
if (!OwningInstance)
{
return;
}
//获取动画实例所属的actor
AActor* ownerActor = OwningInstance->GetOwningActor();
if (!ownerActor)
{
return;
}
//获取渲染组件,用来读取Socket位置
UActorComponent* ac = ownerActor->GetComponentByClass(USceneComponent::StaticClass());
if (!ac)
{
return;
}
USceneComponent* RenderComp = Cast(ac);
if (!RenderComp)
{
return;
}
//获取socket的世界位置
FVector socketLocation = RenderComp->GetSocketLocation(socketName);
if (ownerActor->Implements())
{
ICombat::Execute_INT_AttackDetection(ownerActor,socketLocation, BoxExtent);
}
}

由于这个蓝图接口是角色类调用的,

所以,在角色类重载

virtual void INT_AttackDetection_Implementation(FVector boxPosition, FVector boxExtension) override;

由于还用到了其他蓝图接口,所以暂时让蓝图实现,即

// 扩展入口:蓝图 / C++ 均可重写, UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Combat | Attack") void ProcessHitResult(AActor* Target, float Force); virtual void ProcessHitResult_Implementation(AActor* Target, float Force) {}

void AMyPaperZDCharacter::INT_AttackDetection_Implementation( FVector boxPosition, FVector boxExtension)
{
//如果死亡,则返回
if (IsDead)
{
return;
}
//构建BoxOverlap参数
TArray<TEnumAsByte> objectTypes;
objectTypes.Add(EObjectTypeQuery::ObjectTypeQuery3); //pawn类型

//忽略玩家自身 TArray<AActor*> actorsToIgnore; actorsToIgnore.Add(this); //执行盒体检测 TArray<AActor*> outActors; bool bHasOverlap = UKismetSystemLibrary::BoxOverlapActors( this, boxPosition, boxExtension, objectTypes, nullptr, actorsToIgnore, outActors ); if (!bHasOverlap) { return; } //根据连击数设置推力 float force = (comboIndex == 0) ? 200.0f : 600.0f; //遍历所有重叠actor for (AActor* target : outActors ) { if (!target) { continue; } bool bIsEnemy = target->ActorHasTag(FName("enemy")); if (!bIsEnemy) { continue; } this->ProcessHitResult(target, force); }

}

在蓝图中暂时保留

相关新闻

  • Beyond Compare 5永久激活终极指南:简单三步解锁专业版功能
  • 终极指南:如何用现代C++库OpenXLSX高效处理Excel文件
  • 工业信号隔离与STM32电机控制优化方案

最新新闻

  • 亨得利官方名表服务中心|热线电话及门店地址权威信息公告(2026年7月更新) - 亨得利官方博客
  • Claude Fable 5 扩展:免费访问扩展
  • Tailwind IntelliSense在Cursor中卡顿?1个tsconfig.json参数+2个Cursor插件禁用项+1次LSP重启,5分钟解决97%的智能提示延迟问题
  • 积家中国官方售后服务网络全指南|官网认证地址及电话全新启用(2026年7月最新) - 积家中国服务中心
  • LangChain4J:Java原生LLM应用开发核心框架解析
  • 深度技术解析:NxNandManager如何实现Nintendo Switch NAND存储的专业管理

日新闻

  • OpenClaw本地化部署:xParse文档解析引擎实战指南
  • 蓝牙 5.4 协议栈深度解析:从 HCI 到 L2CAP 的 7 层数据流
  • PyTorch nn.CrossEntropyLoss 实战:3种权重设置与标签平滑对比(附代码)

周新闻

  • 基于YOLOv12的番茄成熟度智能检测系统开发
  • 终极RimWorld模组管理指南:用RimSort告别模组冲突烦恼
  • AI Agent框架开发:从理论到实践的完整指南

月新闻

  • 2026年6月公司网站搭建最新热门渠道测评:四大低成本/零代码平台对比+避坑
  • 【Linux】Linux arm 编译QT程序,出现expected “}“报错
  • 【MATLAB例程】四基站二维AOA定位与距离辅助增强对比仿真。基于角度观测和测距修正的固定目标平面定位精度分析

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号