🔫CoopGame08-游戏模式

type
status
date
slug
summary
tags
category
icon
password
跟随B站up主“技术宅阿棍儿”的教程制作的笔记。教程链接 ###1.概要
  • 用GameMode生成回合制的敌人
  • 击杀奖励
  • 处理游戏状态,例GameOver
  • 玩家重生
  • 搭建场景 ###2.EQS(场景查询系统)
1.开启(各引擎版本不同)
1.编辑器偏好设置-通用-实验性功能-AI-Environment Query System 2.插件-Environment Query Editor(4.27版本默认开启)
2.新建蓝图类EnvQueryContext_BotSpawns继承EnvQueryContext_BlueprintBase环境查询情景蓝图基础。
重载提供Actor集ProvideActorSet函数,获取TargetPoint的所有Actor
notion image
3.新建蓝图类EnvQueryContext_AllPlayers继承EnvQueryContext_BlueprintBase。
重载提供Actor集ProvideActorSet函数,获取SCharacter的所有Actor
notion image
4.创建环境查询EQS_FindSpawnLocation(右键-人工智能-环境查询)
从根拉出Points:Grid设置
notion image
右键添加测试Distance
notion image
编写BP_TestGameMode蓝图
notion image
场景中添加目标点。
###3.增加回合机制
1..创建SGameModeC++类继承GameModeBaseC++类并编写。
SGameMode.h
SGameMode.cpp
修改BP_TestGameMode蓝图类中的BeginPlay节点为SpawnNewBot,运行结果:生成当前关卡的AI后继续生成后续关卡的AI。
2.完善回合机制
SHealthComponent.h
SHealthComponent.cpp
SGameMode.h
SGameMode.cpp
确认BP_TestGameMode蓝图类中的Tick间隔是否为Cpp中设置的1秒,同时删除场景中其他测试的角色,只留出生点,运行结果:在当前关卡的AI都死亡后才生成下一关卡的AI。
3.实现GameOver状态
SGameMode.h
SGameMode.cpp
运行结果:当玩家死后,日志打印游戏结束。
###4.使用GameState类同步游戏状态
1.创建SGameState类,继承GameStateBase类的C++类。
SGameState.h
SGameState.cpp
2.修改SGameMode代码,设置每个阶段的游戏状态。
SGameMode.h
SGameMode.cpp
3.创建BP_GameState蓝图类,继承SGameState C++类,编写打印状态的蓝图。
notion image
4.修改BP_TestGameMode中的游戏状态类为BP_GameState
5.可以选择设置AI掉下平台就摧毁。
notion image
6.运行结果:左上角正确显示游戏状态
###5.使用PlayerState类同步玩家状态
1.创建SPlayerState C++类,继承PlayerState C++类,编写添加分数的函数AddScore。
SPlayerState.h
SPlayerState.cpp
2.SGameMode新委托,需要在蓝图中绑定。
SGameMode.h
SGameMode.cpp
3.修改SHealthComponent类,标记死亡。并调用GM中的委托,广播出去有人死了
SHealthComponent.h
SHealthComponent.cpp
4.编写BP_TestGameMode蓝图类,首先确保GM中的玩家状态类为SPlayerState
notion image
###5.玩家重生机制
1.玩家复活是在准备下一个关卡之后复活,修改SGameMode类
SGameMode.h
SGameMode.cpp
2.运行结果:在玩家没有全部死亡,并且通关后,会复活已经死亡的角色
###5.快速搭建简单场景工具BSP-Tools
Prev
CoopGame07-增强道具
Next
CoopGame09-进阶AI
Loading...
Catalog