ue4如何判断大惊小怪造句是不是在飞行

原文链接:http://blog.csdn.net/frabbit_on_fire/article/details/#comments
├── Engine
│ & ├── Binaries 二进制可执行文件文件夹
│ & │ & ├── DotNET .net 工程 (Mac下是Mac文件夹 编辑器或者崩溃报告器)
│ & │ & └── ThirdParty arm,mono,penal,oculus等的可执行文件
│ & ├── Build 编译时各个平台的集成环境 配置或者依赖
│ & │ & ├── Android 安卓平台
│ & │ & ├── BatchFiles 编译的批处理文件bat sh
│ & │ & ├── BuildFarm 平台兼容perl
│ & │ & ├── Graph 图表
│ & │ & ├── HTML5 html5 json2.js
│ & │ & ├── IOS ios
│ & │ & ├── Mac mac
│ & │ & └── TVOS 苹果电视
│ & ├── Config 各个平台的参数
│ & │ & ├── Android
│ & │ & ├── HTML5
│ & │ & ├── IOS
│ & │ & ├── Linux
│ & │ & ├── Localization 本地化配置文件
│ & │ & ├── Mac
│ & │ & └── Windows
│ & ├── Documentation 文档
│ & │ & ├── Extras 额外的东西
│ & │ & └── Source
│ & ├── Extras 额外的工具
│ & │ & ├── AndroidWorks
│ & │ & ├── LLDBDataFormatters
│ & │ & ├── MayaVelocityGridExporter
│ & │ & ├── Maya_AnimationRiggingTools
│ & │ & ├── ThirdPartyNotUE
│ & │ & ├── VisualStudioDebugging
│ & │ & └── VisualStudioSnippets
│ & ├── Plugins 集成的插件
│ & │ & ├── 2D 2d游戏开发的东西(2d的精灵,地图块等)
│ & │ & ├── Blendables 混合(光传播)
│ & │ & ├── Developer 开发方面的(代码访问)
│ & │ & ├── Editor 编辑器(公司的调查,mac图像转换 插件查看器 speedtree 查找)
│ & │ & ├── Experimental 一些实验性的插件
│ & │ & ├── Media 多媒体(视频,音效)
│ & │ & ├── Messaging & 通信(UDP)
│ & │ & ├── MovieScene &影视场景(levelsequence matinee)
│ & │ & ├── NetcodeUnitTest 网络代码单元测试
│ & │ & ├── Runtime 各种运算时环境(移动平台,vr,movieplayer)
│ & │ & ├── ScriptPlugin 脚本(lua脚本支持)
│ & │ & └── Slate
│ & ├── Programs 依赖的一些程序
│ & │ & ├── CrashReportClient
│ & │ & ├── ShaderCompileWorker
│ & │ & ├── UnrealFrontend
│ & │ & ├── UnrealGameSync
│ & │ & ├── UnrealHeaderTool
│ & │ & └── UnrealLightmass
│ & ├── Shaders 着色器 (hlsl glsl usf:ue4引擎跨平台shader)
│ & │ & └── StandaloneRenderer 独立的着色器 (hlsl glsl )
│ & └── Source 源码
│ & & & ├── Developer 开发者用的源码
│ & & & ├── Editor 编辑器UI源码
│ & & & ├── Programs ue4的程序源码
│ & & & ├── Runtime 引擎核心源码
│ & & & └── ThirdParty 第三方库源码
├── Samples 例子(空)
│ & ├── MobileStarterContent 编辑器移动端第一次打开显示的东西
│ & │ & ├── Build
│ & │ & └── Config
│ & └── StarterContent 编辑器第一次打开的显示的东西
│ & & & ├── Build
│ & & & └── Config
└── Templates 游戏模板
& & ├── FP_FirstPerson 第一人称游戏模板 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── FP_FirstPersonBP 第一人称游戏 蓝图模板
& & │ & └── Config
& & ├── TP_2DSideScroller 2D滚屏游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_2DSideScrollerBP 2D滚屏游戏 蓝图模板
& & │ & └── Config
& & ├── TP_FirstPerson 第一人称游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_FirstPersonBP 第一人称游戏 蓝图模板
& & │ & └── Config
& & ├── TP_Flying 飞行类游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_FlyingBP 飞行类游戏 蓝图模板 蓝图模板
& & │ & └── Config
& & ├── TP_Puzzle 小游戏 消除 解密游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_PuzzleBP 小游戏 消除 解密游戏 蓝图模板
& & │ & └── Config
& & ├── TP_Rolling 滚动游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_RollingBP 滚动游戏 蓝图模板
& & │ & └── Config
& & ├── TP_SideScroller 横屏滚屏游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_SideScrollerBP 横屏滚屏游戏 蓝图模板
& & │ & └── Config
& & ├── TP_ThirdPerson 第三人称游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_ThirdPersonBP 第三人称游戏 蓝图模板
& & │ & └── Config
& & ├── TP_TopDown 上下游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_TopDownBP 上下游戏 蓝图模板
& & │ & └── Config
& & ├── TP_TwinStick 双摇杆游戏 &c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_TwinStickBP 双摇杆游戏 蓝图模板
& & │ & └── Config
& & ├── TP_Vehicle 运输类游戏 赛车 赛艇 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_VehicleAdv 高级运输类 游戏 c++模板
& & │ & ├── Config
& & │ & └── Source
& & ├── TP_VehicleAdvBP 高级运输类 游戏 蓝图模板
& & │ & └── Config
& & ├── TP_VehicleBP 高级运输类 游戏 蓝图模板
& & │ & └── Config
& & └── TemplateResources 模板游戏资源
& & & & ├── High &高材质
& & & & └── Standard 一般材质
131 directories
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:6505次
排名:千里之外
原创:23篇
转载:12篇
(3)(5)(1)(1)(2)(8)(9)(2)(1)(3)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'1、本文为题主在学习中翻译,同时在UE4.10.2 版本上尝试运行,翻译过程中遇到翻译不出会暂时留白,翻译有误请指出,谢谢!
2、本文在翻译过程中遇到题主不懂的地方可能会添加题主的知识扩展链接。
3、转载请注明出处。谢谢!
4、原文地址:
---------------------------------------------------------------------------------------------
在此对题主好友Erin表示感谢。感谢Erin在这一系类中指出并校正有误的地方。
-------------------------------------------------------------------------------------------
第一人称射击C++教程
Warning:&This tutorial may be outdated for newer versions of Unreal Engine.
警告:该教程可能不适用新版本虚幻引擎
PS:以下目录默认链接为官网连接,翻译完成后将更改为CSDN上翻译后的博客链接。不便之处,还请原谅。谢谢!
PS:已更改为翻译后CSDN博客链接。
PS:所有章节已整合在一起。
PS:该教程适合入门,涉及到了C++、蓝图、碰撞、动画等知识,按照该教程,可初步熟悉UE4引擎。
Contents(目录)
Over the course of this tutorial, you will transform a blank project template into the beginnings of a first-person shooter, with a character that moves and strafes, camera control, and projectiles you can fire at the environment.
Using C++, you will create a GameMode, Character and HUD.
本教程中,你会从一个空白的项目模板入手,从而开始第一人称射击,在该环境中包括了角色的移动和扫射、摄像机控制,以及你可以开火的子弹。使用C++,你可以创建GameMode、角色和HUD。
---------------------------------------------------------------------------------------------
We will create a blank project as the starting point for our FPS game, using Unreal Engine 4's Project Browser.
我们将使用UE4的项目浏览器,新建空项目作为我们FPS游戏的初始点。
1. Open Unreal Editor.
打来虚幻编辑器。
2. In the&Project Browser, click on the&New Project&tab.
在项目浏览器中点击NewProject标签页。
3. Select the Blank project.
选择Blank project。
4. Name the project FPSProject and uncheck the&Copy starter content into new project?&checkbox. (Uncheck &Include starter content checkbox& for UE 4.2.0)
项目名命名为FPSProject,不勾选Copy starter content into new project?选项框。(PS:UE4.10选择&without
starter content&)
Note that some of the code samples provided in this tutorial will require alteration if the project's name is different, and we will make note of that at the appropriate step.
要的注意的是,如果项目名不一样的话,则需要改变本教程提供的一些代码样本,我们会在相应步骤进行注释。
5. Click on&Create.
点击Create。
6. Your project is now open in Unreal Editor. You can play in the starting level by clicking on the&Play In&button in the Level Editor Toolbar. The WASD keys will allow you to fly around within the level, and the mouse will aim your camera.
Press&Escape&when you are ready to exit Play in Editor (PIE) mode.
现在,你的工程已经在虚幻编辑器打开。你可以点击关卡编辑工具栏上的Play按键从而在开始关卡中玩耍了。其中WASD按键可以让你在关卡中飞行,鼠标可以移动你的相机视角。按下Escape即可退出PIE模式。
7. Create a Maps folder within the Content folder.
在Content文件夹下新建Maps文件夹。
8. In the&File&menu, select&Save as...&to save your map as FPSMap within the Maps folder.
在File&菜单中选择Save as...&将你的map命名为FPSMap保存到Maps文件夹下
9. In the&Edit&menu, click on&Project Settings.
在Edit&菜单中,选择Project Settings。
10. Under the&Game&heading on the left side of the&Project Settings&tab, click on&Maps & Modes.
在Project Settings&标签左侧Game标题下,点击。Maps
11. Using the dropdown, select&FPSMap&as the&Editor Startup Map. Now, whenever you re-open your project in the editor, you will automatically load this map.
使用下拉,选择FPSMap作为Editor Startup Map。现在,无论你何时在编辑器中重启你的项目,都会自动加载该map。
12. Close the Project Settings menu.
关闭Project Settings菜单
---------------------------------------------
Let's create a GameMode. A GameMode contains the definition of the game itself, such as game rules, win conditions, etc. It also sets the default classes to use for some basic gameplay framework types, including Pawn, PlayerController, and HUD. Before we set
up our FPS character, we need to create the GameMode that will reference it.
创建GameMode。GameMode包含了游戏本身的定义,如游戏规则,过关条件等等。它还为游戏架构类型设置了默认类,包括Pawn, PlayerController, and HUD。在我们创建我们的FPS角色之前,我们需要创建一个与之相关的GameMode。
First, we are going to use the C++ Class Wizard to add a new class to our project.
首先,我们将使用C++类向导为项目添加一个类。
1.In the File menu, select&Add Code to Project.
在File菜单中,选择Add Code to Project。
2. Scroll down and select GameMode as the parent class. Click Next.
向下滚动,选择GameMode作为父类,点击Next.
3. Name the new class&FPSGameMode, then click&Create.
类名命名为FPSGameMode,点击Create。
<span style="color:#. Click on Yes to open the class in Visual Studio or XCode for editing.
点击Yes在VS或XCode中打开进行编辑。
Since this is the first code we've added to the project, the wizard will also create the initial files needed to compile and run our project.
由于这是我们添加到项目中的第一个代码,该向导还将创建项目编译和运行所需的初始文件。
We will add a log message to the FPSGameMode, so that when we start playing in our level, we can see that we are actually using our new GameMode. We will add code to FPSGameMode's constructor, so that it will run when gameplay begins.
我们将为FPSGameMode添加一个日志信息,这样当我们开始在我们的关卡中运行的时候,我们可以看到,我们实际上是在使用新的GameMode。我们将代码添加到FPSGameMode构造函数中,这样它会游戏开始时运行。
1. Your code IDE will open.
打开你的代码编辑器。
2. In the Solution Explorer, expand&FPSProject & Source & FPSProject.
在Solution Explorer中,按FPSProject & Source & FPSProject扩展开。
3. Here, you will see the header file for your new&FPSGameMode&class, FPSGameMode.h. Double-click it to open it for editing.
在这里,你会看到你新建类FPSGameMode的头文件——FPSGameMode.h。双击打开。
4. Find the class declaration, which looks like:
找到类声明,如下:
class FPSPROJECT_API AFPSGameMode : public AGameMode
GENERATED_BODY()
5. Under&GENERATED_BODY(), add the following lines then save the file.
在GENERATED_BODY()下,添加下面代码后保存
virtual void StartPlay() override; // Note that engine version 4.3 changed this method's name to StartPlay(), because of this engine versions before 4.3, or older tutorials, use BeginPlay()
This function declaration will allow you to override the StartPlay() function inherited from the `AActor` class, so that you can print a message to the screen when gameplay begins.
该函数声明将重写继承自 'AActor' 的StartPlay()函数,因此你可以在游戏开始时在屏幕上输出消息。
Note: 4.6 needs below line to be included (before or after StartPlay(). This is the definition of constructor whose signature is also different from older versions.
注意:4.6需要加入以下代码(在StartPlay()之前之后,这是与旧版本签名不同的构造函数的定义)
AFPSGameMode(const FObjectInitializer& ObjectInitializer);
6. Open FPSGameMode.cpp. It is located in&FPSProject & Source & FPSProject&as well.
打开FPSGameMode.cpp,它同样位于FPSProject & Source & FPSProject。
If your project has a different name, your code will be located in&[ProjectName] & Source & [ModuleName]. The module name is the same as your project name because you used the&C&#43;&#43; Class Wizard.
如果你有不同的项目名,你的代码将位于&[ProjectName] & Source & [ModuleName].模块名和你的项目名一致,因为你是用的C&#43;&#43;类向导。
First, at the top of the file, add the following line under the other #include lines:
首先,在文件的开头,包含如下头文件
#include &Engine.h& //for version 4.4&#43;
// Note that this may no longer be necessary as this file will likely already include [ProjectName].h, which, by default, will include &Engine.h& itself
7. Find FPSGameMode's constructor. It looks like:
找到FPSGameMode的构造函数,如下:
Note: In 4.6 this is no longer correct as the procedure for constructors has changed, you will not find this code.&You will need to write the following line of code in if it is not present&For
users of previous versions, FPostConstructInitializeProperties is replaced with FObjectInitializer and variable name PCIP with ObjectInitializer (though variable name can be anything, its recommended to change as a good practice)
注意:在4.6这不再正确,因为构造函数的程序已改变。你不会找到这条代码。如果它不存在,你需要编写以下代码。对于以前版本的用户,FPostConstructInitializeProperties已替换为FObjectInitializer,且变量名由PCIP替换为ObjectInitializer(虽然变量名可以是任何东西,它推荐的做法更为妥当)
AFPSGameMode::AFPSGameMode(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
The prefixed name of FPSGameMode is AFPSGameMode, because it derives from a class which eventually derives from the Actor class.
FPSGameMode 的前缀名为 AFPSGameMode,因为他的父类继承与Actor类
8. After the constructor, add the following lines, then save the file.
在构造函数后面,添加以下代码并保存。
// Note that engine version 4.3 changed the method's name to StartPlay(), because of this engine versions before 4.3, or older tutorials, use BeginPlay()
void AFPSGameMode::StartPlay()
Super::StartPlay();
StartMatch();
if (GEngine)
GEngine-&AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT(&HELLO WORLD&));
This function definition will print &HELLO WORLD& to the screen in yellow text when gameplay begins.
在游戏开始时,该函数将在屏幕上打印出黄色文本&HELLO
We will now compile our project, so that we can see our code changes reflected in the game. If you are using Unreal 4.6 or below, you need to close the editor, compile, and then reopen the project in the editor to reload the game module.现在编译我们的项目,这样就可以在游戏中我们
代码实现。如果你使用4.6或更低版本,你需要关掉编辑器,编译,然后在编辑器重启项目或则重新加入游戏模块。(PS:入门4.10,表示不需要……^_^)。
1. If you are using Visual Studio, make sure that you have set up Visual Studio for compiling with Unreal Engine.
如果你使用VS,确保你设置了VS可为UE编译。
2. Close Unreal Editor. (Not required in 4.7)
关掉虚幻编辑器(4.7不需要,PS:4.10同样不要)。
4. After the build finishes, open Unreal Editor, and then open&FPSProject.
完成build,打开FPSProject项目。
We need to set the project to use FPSGameMode as the default GameMode.
我们需要在项目中将FPSGameMode设置为默认的GameMode.
1. In the&Edit&menu, click on&Project Settings.
Edit -&&Project Settings.
2. Under the&Game&heading on the left side of the&Project Settings&tab, click on&Maps & Modes.
在Project Settings&标签左侧Game标题下,点击。Maps
3. Select&FPSGameMode&in the Default GameMode dropdown.
在Default &GameMode下拉列表中选择FPSGameMode
4. Close the Project Settings menu.
关闭Project Settings 菜单。
5. Click on the&Play In&button in the Level Editor Toolbar. &HELLO WORLD& should be displayed in the upper left corner of the viewport.
点击Play.Viewport左上角出现&HELLO WORLD&。
You can also look in the&Scene Outliner&while your game is running to see&FPSGameMode&listed.
游戏运行时,在Scene Outliner&中可以看到FPSGameMode&.
<span style="color:#. Press&Escape&to exit Play in Editor (PIE) mode.
按下Escape退出PIE模式
--------------------------------------------------------------------------------------------------------------
PS:按照以上教程,题主在UE4.10.2版本中实现上述功能。
#pragma&once&&
#include&&GameFramework/GameMode.h&&&
#include&&MyFPSProjectGameMode.generated.h&&&
UCLASS()&&
class&MYFPSPROJECT_API&AMyFPSProjectGameMode&:&public&AGameMode&&
&&&&GENERATED_BODY()&&
&&&&virtual&void&StartPlay()&&&
&&&&AMyFPSProjectGameMode(const&FObjectInitializer&&ObjectInitializer);&&
#include&&MyFPSProject.h&&&
#include&&MyFPSProjectGameMode.h&&&
AMyFPSProjectGameMode::AMyFPSProjectGameMode(const&FObjectInitializer&&ObjectInitializer):Super(ObjectInitializer)&&
void&AMyFPSProjectGameMode::StartPlay()&&
&&&&Super::StartPlay();&&
&&&&StartMatch();&&
&&&&if&(GEngine)&&
&&&&&&&&GEngine-&AddOnScreenDebugMessage(-1,&5.f,&FColor::Yellow,&TEXT(&HELLO&WORLD&));&&
------------------------------------------------------------------------------------------------------------
The engine has a built-in class called DefaultPawn which is a Pawn with some simple disembodied flying movement. We want to have a human-like avatar walking on the ground, so let's create our own Pawn to control. The engine includes a class for this called
Character, which derives from Pawn but has built in functionality for bipedal movement like walking, running, and jumping. We will use Character as the base class for our FPS Pawn.
引擎有一个内置的DefaultPawn类,它是一个可简单飞行运动的Pawn。我们希望有类&#20284;人类行走的avatar,那么就创建一个可控制的Pawn把。引擎含有一个叫做Character的类,它继承自Pawn,但是具有类&#20284;行走、跳跃的双足运动功能,我们将使用Character作为FPS
Pawn的基类
Again, we will use the C&#43;&#43; Class Wizard to add this new class to our project. It is possible to manually add the *.h and *.cpp files to your Visual Studio solution to add new classes, but the C&#43;&#43; Class Wizard fills in header and source templates which set up
the Unreal-specific macros for us, which simplifies the process.
接着,我们使用C&#43;&#43;类向导新建类到我们的项目中。可以手动添加Visual Studio
1. In the File menu, select&Add Code to Project.
在File菜单中,选择&Add Code to Project.
2. Scroll down and select&Character&as the parent class. Click&Next.
下滑选择Character&作为基类,点击Next。
3. Name the new class&FPSCharacter, then click&Create.
新类命名为FPSCharacter,点击Create。
4. Click on&Yes&to open the class in Visual Studio for editing.
点击Yes并在VS中打开类。
5. Visual Studio will prompt you asking to reload the project, since the&C&#43;&#43; Class Wizard&modified it. Select&Reload.
Visual Studio会提示你是否重新加载项目,由于C &#43;&#43;类向导修改了它,因此选择刷新。
First, we will edit our&GameMode, so that FPSCharacter is the default Pawn used when starting gameplay.
首先,我们编辑GameMode,从而开始游戏时FPSCharacter作为被使用的默认Pawn.
1. First go to FPSGameMode.h. Below GENERATED_BODY() we will now add a constructor for the class, the following will be what our class looks like now (Engine Version 4.6).
首先前往GENERATED_BODY() 下为类添加构造函数,以下就是我们的程序(UE4.6)
class FPSPROJECT_API AFPSGameMode : public AGameMode
GENERATED_BODY()
AFPSGameMode(const FObjectInitializer& ObjectInitializer);
// Our added constructor
virtual void StartPlay() override;
2. Return to FPSGameMode.cpp. First, at the top of the file, add the following line under the other #include lines:
返回FPSGameMode.cpp。首先,在文件顶部其他的#include下添加下面的的头文件
#include &FPSCharacter.h&
3. Then, we will find the constructor we previously added in FPSGameMode.cpp:
接着,找到我们之前在FPSGameMode.cpp添加的构造函数。
AFPSGameMode::AFPSGameMode(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
4. And following that we add the following line to the constructor:
在构造函数添加下面的代码
DefaultPawnClass = AFPSCharacter::StaticClass();
This tells the GameMode which type of Pawn to spawn for the player when starting the game.
它会告诉GameMode在游戏启动时那种类型的Pawn会生成给玩家(PS:spawn for不知道怎么翻译好)
The constructor for FPSGameMode will now look like:
现在FPSGameMode的构造函数是这样的:
AFPSGameMode::AFPSGameMode(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
DefaultPawnClass = AFPSCharacter::StaticClass();
Now, save the files.
现在,保存文件。
Let's also add an on-screen message to FPSCharacter, so we can be sure our new class is being used properly.
让我们也给FPSCharacter添加一个屏幕消息,以确保我么的新类被正确使用。
1. Open FPSCharacter.h. It is located in FPSProject & Source & FPSProject.
打开FPSCharacter.h,它位于&FPSProject & Source & FPSProject.
If your project has a different name, your code will be located in [ProjectName] & Source & [ModuleName]. The module name is the same as your project name because you used the C&#43;&#43; Class Wizard.
如果你的项目名和教程不同,你的代码会位于[项目名] & Source & [模块名],项目名与模块名一致。
2. Find the class declaration, which looks like:
找到类声明,类&#20284;这样:
class FPSPROJECT_API AFPSCharacter : public ACharacter
GENERATED_BODY()
3. Under&GENERATED_BODY(), add the following line, then save the file.
在GENERATED_BODY()下,添加以下代码:
virtual void BeginPlay() override;
This function declaration will allow you to override the BeginPlay() function inherited from the AActor class, so that you can print a message to the screen when gameplay begins.
这个函数声明允许你重写继承自AActor的BeginPlay()函数,从而在启动游戏时屏幕输出消息。
4. Now open FPSCharacter.cpp and add the following lines, then save the file.
打开FPSCharacter.cpp,添加下面代码并保存。
void AFPSCharacter::BeginPlay()
Super::BeginPlay();
if (GEngine)
GEngine-&AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT(&We are using FPSCharacter!&));
This function definition will print &We are using FPSCharacter!& to the screen in blue text when gameplay begins.
游戏启动时,该函数会在屏幕显示蓝色文本&We are using FPSCharacter!&
We will again close the editor and compile our project, so that we can see our code changes reflected in the game. (Note that you should be able to hot-reload if you are using the latest engine version, which means you can compile
without closing the Unreal Editor.)
关掉编辑器编译项目,可以在游戏中反映出代码的改变。
1. Close Unreal Editor.
关掉虚幻编辑器
编译(PS:4.10版本可直接编译,因为它具有热更新功能)
3. After the build finishes, open Unreal Editor, and then open FPSProject.
编译完成后,打开虚幻编辑器,打开FPSProject.
4. Click on the Play In button in the Level Editor Toolbar. Your new Character does not have any movement controls yet, so you will not be able to move around in the level. So, if you are stuck and unable to move, you are using
the FPSCharacter as your Pawn correctly! Your log message should also be displayed on the screen.
点击Play.你的Character还没有运动控制,所以你还不能在关卡中移动。所以如果你动不了,便表示正确使用了作为Pawn的FPSCharacter.你的日志消息也会显示在屏幕上。(PS:以后类&#20284;点击关卡编辑工具栏上的Play按键就直接说点击Play了,这几个章节用下来,基本上能找到哪里是哪里,就不再赘述了。)
You can also look in the&Scene Outliner&while your game is running to see&FPSCharacter&listed.
5. Press&Escape&to exit Play in Editor (PIE) mode.
---------------------------------------------------------
4.10上运行,源码如下(PS:题主GameMode类命名为MyFPSProjectGameMode了)
MyFPSProjectGameMode.h
#pragma&once&&
#include&&GameFramework/GameMode.h&&&
#include&&MyFPSProjectGameMode.generated.h&&&
UCLASS()&&
class&MYFPSPROJECT_API&AMyFPSProjectGameMode&:&public&AGameMode&&
&&&&GENERATED_BODY()&&
&&&&virtual&void&StartPlay()&&&
&&&&AMyFPSProjectGameMode(const&FObjectInitializer&&ObjectInitializer);&&
MyFPSProjectGameMode.cpp
#include&&MyFPSProject.h&&&
#include&&MyFPSProjectGameMode.h&&&
#include&&FPSCharacter.h&&&
AMyFPSProjectGameMode::AMyFPSProjectGameMode(const&FObjectInitializer&&ObjectInitializer):Super(ObjectInitializer)&&
&&&&DefaultPawnClass&=&AFPSCharacter::StaticClass();&&
void&AMyFPSProjectGameMode::StartPlay()&&
&&&&Super::StartPlay();&&
&&&&StartMatch();&&
&&&&if&(GEngine)&&
&&&&&&&&GEngine-&AddOnScreenDebugMessage(-1,&5.f,&FColor::Yellow,&TEXT(&HELLO&WORLD&));&&
FPSCharacter.h
#pragma&once&&
#include&&GameFramework/Character.h&&&
#include&&FPSCharacter.generated.h&&&
UCLASS()&&
class&MYFPSPROJECT_API&AFPSCharacter&:&public&ACharacter&&
&&&&GENERATED_BODY()&&
&&&&AFPSCharacter();&&
&&&&virtual&void&BeginPlay()&&&
&&&&virtual&void&Tick(&float&DeltaSeconds&)&&&
&&&&virtual&void&SetupPlayerInputComponent(class&UInputComponent*&InputComponent)&&&
FPSCharacter.cpp
#include&&MyFPSProject.h&&&
#include&&FPSCharacter.h&&&
AFPSCharacter::AFPSCharacter()&&
&&&&PrimaryActorTick.bCanEverTick&=&true;&&
void&AFPSCharacter::BeginPlay()&&
&&&&Super::BeginPlay();&&
&&&&if&(GEngine)&&
&&&&&&&&GEngine-&AddOnScreenDebugMessage(-1,&5.f,FColor::Blue,&TEXT(&We&are&using&FPSCharater&));&&
void&AFPSCharacter::Tick(&float&DeltaTime&)&&
&&&&Super::Tick(&DeltaTime&);&&
void&AFPSCharacter::SetupPlayerInputComponent(class&UInputComponent*&InputComponent)&&
&&&&Super::SetupPlayerInputComponent(InputComponent);&&
--------------------------------------------------------------------------------------------------------------
Let's get our new Character moving around.
让我们的新角色遛起来。
We will go through specifics of input processing in the next several steps, but you may also find the general overview of input framework useful to refer to.
我们将在接下来的几个步骤了解input(输入)细节,但你也会发现input框架的概述&#20540;得去参考(PS:这里可能是说参考官方说明文档)。
The input controls for walking around in the world, such as WASD or arrow keys, are usually set up with axis mappings.
如WASD或者方向键的行动输入控制,通常设置了轴映射。
Map keyboard, controller, or mouse inputs to a &friendly name& that will later be bound to continuous game behavior, such as movement. The inputs mapped in AxisMappings are continuously polled, even if they are just reporting that their input value is currently
zero. This allows for smooth transitions in movement or other game behavior, rather than the discrete game events triggered by inputs in ActionMappings. Hardware axes, such as controller joysticks, provide degrees of input, rather than discrete 1 (pressed)
or 0 (not pressed) input. That is, they can be moved to a small degree or a large degree, and your character's movement can vary accordingly. While these input methods are ideal for providing scalable amounts of movement input, AxisMappings can also map common
movement keys, like WASD or Up, Down, Left, Right, to continuously-polled game behavior.
映射键盘、控制器或者输入 到一个“友好名字”将会在之后绑定到连续的游戏行为,比如行动。轴映射中的的输入映射不断轮询,即使他的输入&#20540;近乎为0。它允许在运动或其他游戏行为中平滑过渡,而不是由ActionMappings中的输入触发的离散游戏事件。如摇杆控制器提供了输入量而不是离散的1(按下)或0(抬起)输入。也就是说,它们可大可小,而你的角色运动速度也会随之而变。虽然这些输入方法很好的提供了可伸缩的运动输入量,但是轴映射也可以映射常见的移动按键,如WASD,上下左右,来不断轮询游戏行为。
First, we will set up axis mappings for the W, A, S, and D keys.
首先,为WASD设置轴映射。
In the&Edit&menu, click on&Project Settings.选择Edit中的&Project Settings。Under the&Engine&heading on the left side of the&Project Settings&tab, click on&Input.在Engine标题下面找到Input.Under&Bindings, click on the plus sign next to&Axis Mappings&(If nothing appears, click the arrow to the left of Axis Mappings).在Binding下点击Axis Mappings&加号(如果没事时,点击右边的箭头)。Type &MoveForward& into the text field that appears, then click on the arrow to the left of the text box to expand the axis binding options.在编辑框中输入&&MoveForward&&,点击箭头扩展选项。In the dropdown menu, select&W. Your input settings should now look like the following:在下拉列表中选择W。你的输入设置应该会如下图所示:
6. Now, click on the plus sign next to&MoveForward
点击MoveForward旁边的加号
7. In the second dropdown menu, select&S. Type &-1& in the&Scale&field. Your input settings should now look like the following:
在第一个下拉菜单中选择S,Scale中输入-1,设置如下
8. Under&Bindings, click on the plus sign next to&Axis Mappings.
点击Axis Mappings旁的加号.
9. Type &MoveRight& into the text field that appears, then click on the arrow to the left of the text box to expand the axis binding options.&&MoveRight& .
10. In the dropdown menu, select&D. Your input settings should now look like the following:
如添加“W”一样添加“D”.
11. Under&Bindings, click on the plus sign next to&MoveRight.
点击MoveForward旁边的加号。
12. In the second dropdown menu, select&A. Type &-1& in the&Scale&field. Your input settings should now look like the following:
如添加“S”一样添加“A”.Scale设置-1.
13. Close the Project Settings menu.
关闭 Project Settings。
14. Switch to your project in Visual Studio.
切换到VS。
15. The Character class has a function called SetupPlayerInputComponent that is called when the PlayerController possesses the Character. We will override this function to bind our own handlers for the MoveForward and MoveRight axis mappings.
当PlayerController操纵Character的时候,Character类有一个名为SetupPlayerInputComponent&方法被调用。我们将重写该方法来绑定自己MoveForward 和MoveRight轴映射的处理程序 。
16. In&FPSCharacter.h, add the following declaration under&virtual void BeginPlay()
:在FPSCharacter.h,在virtual void BeginPlay()下一行添加以下声明:
protected:
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
17. We also want to declare our handler functions, so add these lines under the&SetupPlayerInputComponent&declaration inFPSCharacter.h&and
save the file.
声明自己的处理方法,在FPSCharacter.h&中SetupPlayerInputComponent声明的下一行添加以下代码,保存。
//handles moving forward/backward
UFUNCTION()
void MoveForward(float Val);
//handles strafing
UFUNCTION()
void MoveRight(float Val);
UFUNCTION()
Macro —— UFUNCTION () 宏
The UFUNCTION macro is used above each of these functions. By itself, the UFUNCTION macro makes the engine aware of these functions, so that they can be included in serialization, optimization, and other engine functionality. You may also have noticed the UCLASS
macro above your new FPSGameMode and FPSCharacter class declarations, which does the same thing but for classes, and there is also a UPROPERTY macro for properties. There are a number of specifiers you can supply to these macros to change the function, class,
and property behaviors in the engine, which can be found in ObjectBase.h.
UFUNCTION宏被用于上面的每个方法。通过自身,UFUNCTION宏使引擎意识到这些函数的存在,从而使它们可以被包含于序列化、优化和其他引擎功能。你可能也会在上面的FPSGameMode和FPSCharacter类声明中注意到UCLASS宏为类做同样的事情,还有一个针对属性的UPROPERTY宏。有许多修饰符供你提给宏以改变引擎中的方法、类以及属性行为,它们可以在ObjectBase.h找到。
After setting up our function dhoneclarations, we will implement them in&FPSCharacter.cpp.
完成设置我们的方法声明后,我们将在FPSCharacter.cpp实现它们。
1. First, we will define&SetupPlayerInputComponent. The following lines set up the gameplay key bindings. Add them below the constructor in&FPSCharacter.cpp.
首先,定义SetupPlayerInputComponent,下面代码设置游戏案件绑定,将他们添加到FPSCharacter.cpp中的构造函数的下方。
void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* InputComponent)
// set up gameplay key bindings
InputComponent-&BindAxis(&MoveForward&, this, &AFPSCharacter::MoveForward);
InputComponent-&BindAxis(&MoveRight&, this, &AFPSCharacter::MoveRight);
An InputComponent is a component that defines how to handle input data and can be attached to an actor that wants to receive input.
输入组件定义了如何处理输入数据,可以被附加到需要接受输入的Actor上。
We also need to implement our&MoveForward&and&MoveRight&functions.
In a typical FPS control scheme, the movement axes are camera-relative. That is, &forward& means &direction the camera is pointing&, right means &to the right of the direction the camera is pointing&, and so on. We will get the control rotation from the PlayerController.
Also, since we want to move along the ground even while we are looking up or down (as opposed to trying to push into the ground), our&MoveForward&function
will ignore the pitch component of the control rotation and restrict our input to the XY plane.
我们同样需要实现&MoveForward&和&MoveRight方法。典型的FPS控制方案中,运动轴与相机相对。那就是说,前方代表相机指向的方向,右方代表相机指向方向的右边,以此类推。我们将从PlayerController获取control
rotation.同样,由于我们想在向上或向下看时沿着地面移动(而不是试图进入地下),MoveForward&方法将会忽略control
rotation的俯仰组件,并且限制我们对XY平面的输入。
2. Add the following function to&FPSCharacter.cpp:
添加以下代码到&FPSCharacter.cpp:
void AFPSCharacter::MoveForward(float Value)
if ( (Controller != NULL) && (Value != <span class="nu17" style="color:#8f) )
// find out which way is forward
FRotator Rotation = Controller-&GetControlRotation();
// Limit pitch when walking or falling
if (GetCharacterMovement()-&IsMovingOnGround() || GetCharacterMovement()-&IsFalling() )
Rotation.Pitch = <span class="nu17" style="color:#8f;
// add movement in that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
Our code for&MoveRight&is
very similar, except we will move along a different axis of our control rotation. We also don't need to worry about zeroing the pitch in this case because pitching doesn't affect the Y direction vector.除了沿着不同的旋转轴移动,MoveRight&代码与之类&#20284;。我们无需担心俯仰归零的情况,因为俯仰不影响Y方向向量。
3. Add the following function to&FPSCharacter.cpp:
void AFPSCharacter::MoveRight(float Value)
if ( (Controller != NULL) && (Value != <span class="nu17" style="color:#8f) )
// find out which way is right
const FRotator Rotation = Controller-&GetControlRotation();
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, Value);
以下代码添加到FPSCharacter.cpp:
Let's test out the Character now, and see how we can move throughout the level.
现在,让我们测试下角色吧,看看我们是如在关卡中移动的。
1. Close Unreal Editor.2.&3.
After the build finishes, open Unreal Editor, and then open&FPSProject.4. Click on the&Play
In button&in the&Level Editor Toolbar. You should be able to move and strafe throughout the level, although your camera
will be fixed in place.5. Press&Escape&to exit Play in Editor (PIE) mode.
运行方法如故。
--------------------------------------------------------------------------------------------------------------
4.10 运行成功。
代码如下:
FPSCharacter.h
#pragma&once&&
#include&&GameFramework/Character.h&&&
#include&&FPSCharacter.generated.h&&&
UCLASS()&&
class&MYFPSPROJECT_API&AFPSCharacter&:&public&ACharacter&&
&&&&GENERATED_BODY()&&
&&&&AFPSCharacter();&&
&&&&virtual&void&BeginPlay()&&&
&&&&virtual&void&Tick(&float&DeltaSeconds&)&&&
protected:&&
&&&&virtual&void&SetupPlayerInputComponent(class&UInputComponent*&InputComponent)&&&
&&&&UFUNCTION()&&
&&&&&&&&void&MoveForward(float&Val);&&
&&&&UFUNCTION()&&
&&&&&&&&void&MoveRight(float&Val);&&
FPSCharacter.cpp
#include&&MyFPSProject.h&&&
#include&&FPSCharacter.h&&&
AFPSCharacter::AFPSCharacter()&&
&&&&PrimaryActorTick.bCanEverTick&=&true;&&
void&AFPSCharacter::BeginPlay()&&
&&&&Super::BeginPlay();&&
&&&&if&(GEngine)&&
&&&&&&&&GEngine-&AddOnScreenDebugMessage(-1,&5.f,FColor::Blue,&TEXT(&We&are&using&FPSCharater&));&&
void&AFPSCharacter::Tick(&float&DeltaTime&)&&
&&&&Super::Tick(&DeltaTime&);&&
void&AFPSCharacter::SetupPlayerInputComponent(class&UInputComponent*&InputComponent)&&
&&&&Super::SetupPlayerInputComponent(InputComponent);&&
&&&&InputComponent-&BindAxis(&MoveForward&,&this,&&AFPSCharacter::MoveForward);&&
&&&&InputComponent-&BindAxis(&MoveRight&,&this,&&AFPSCharacter::MoveRight);&&
void&AFPSCharacter::MoveForward(float&Value)&&
&&&&if&((Controller&!=&NULL)&&&&(Value&!=&0.0f))&&
&&&&&&&&&&
&&&&&&&&FRotator&Rotation&=&Controller-&GetControlRotation();&&
&&&&&&&&&&
&&&&&&&&if&(GetCharacterMovement()-&IsMovingOnGround()&||&GetCharacterMovement()-&IsFalling())&&
&&&&&&&&{&&
&&&&&&&&&&&&Rotation.Pitch&=&0.0f;&&
&&&&&&&&}&&
&&&&&&&&&&
&&&&&&&&const&FVector&Direction&=&FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);&&
&&&&&&&&AddMovementInput(Direction,&Value);&&
void&AFPSCharacter::MoveRight(float&Value)&&
&&&&if&((Controller&!=&NULL)&&&&(Value&!=&0.0f))&&
&&&&&&&&&&
&&&&&&&&const&FRotator&Rotation&=&Controller-&GetControlRotation();&&
&&&&&&&&const&FVector&Direction&=&FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);&&
&&&&&&&&&&
&&&&&&&&AddMovementInput(Direction,&Value);&&
PS:等这系类教程翻译并学习完了,再上传源码。以后就不像上面两个两样上传章节源码了。
----------------------------------------------------------------------------------------------------
Let's add the ability to look around and steer with the mouse.
让我们添加拖动鼠标,环顾四周的功能吧。
First, let's set up axis mappings for&Turn&and&LookUp.
首先,为&Turn&和&LookUp设置轴映射。
1. In the&Edit&menu, click on&Project Settings.
进入Project Settings。
2. Under the Engine heading on the left side of the Project Settings tab, click on Input.
在Project Settings中选择Input。
3. Under Bindings, click on the plus sign next to Axis Mappings.
在bingding下点击加号添加轴映射。
4. Type &Turn& into the text field that appears, then click on the arrow to the left of the text box to expand the axis binding options.
输入“Turn”文本,点击它左侧的箭头扩展选项。
5. In the dropdown menu, select&MouseX.
下拉菜单中选择MouseX。
6. Under&Bindings, click on the plus sign next to&Axis Mappings.
点击Axis Mappings旁边的加号。
7. Type &LookUp& into the text field that appears, then click on the arrow to the left of the text box to expand the axis binding options.
类&#20284;“Turn”设置“LookUp”.
8. In the dropdown menu, select&MouseY&and enter &-1& for&Scale. Your input settings should now look like the following:
类&#20284;MouseX设置MouseY,起&#20540;设为-1.设置图如下:
9. Close the Project Settings menu.
关闭Project Settings。
Now, let's add some code to handle those inputs.
现在,为输入控制添加代码。
The Character class defines the two necessary functions for us:&AddYawInput&and&AddPitchInput.
Character为我们定义了两个必要的方法:
If we wanted to do additional processing, such as adding support for sensitivity or axis inversion, we could provide our own functions to adjust the values before passing them to these functions, but in this case let's bind our inputs directly to them.
如果我们想添加一些如支持灵敏度和轴反转的处理,我们可以在给这些方法传递参数前提供自己的函数调整这些&#20540;,但这种情况我们的输入直接绑定它们。
1. Add the following lines to SetupPlayerInputComponent in FPSCharacter.cpp:
在FPSCharacter.cpp中为SetupPlayerInputComponent添加如下代码:
InputComponent-&BindAxis(&Turn&, this, &AFPSCharacter::AddControllerYawInput);
InputComponent-&BindAxis(&LookUp&, this, &AFPSCharacter::AddControllerPitchInput);
Because we only changed an existing function instead of making a new function, we can compile within the editor.
由于我们只是改变现有的方法而不是新建一个方法,因此我们可以在编辑器内直接编译(PS:4.10 哪里都可以编译,这里的意思是不用像MoveFoward那样定义方法了。)。
1. Switch back to Unreal Editor, and click on the&Compile&button.
返回虚幻编辑器点击编译。
2. The&Compiling C&#43;&#43; Code&notification will pop up in the bottom right of the screen. Wait for it to finish - it will say&Compile Complete&and then fade out.
屏幕右下角会显示Compiling C&#43;&#43; Code,他将提示Compile Complete并淡出。
3. Click on the Play In button in the Level Editor Toolbar. Now, you can control the camera direction with your mouse.
Play,你可以通过鼠标控制相机方向。
4. Press&Escape&to exit Play in Editor (PIE) mode.
Esc键退出。
----------------------------------------------------------------------
PS:4.10.2 亲测成功。
--------------------------------------------------------------------------------------------------------------
Now, let's add jumping to our movement abilities. Our movement and camera control steps used axis mappings, which handle continuous inputs needed for those types of controls. There are also action mappings, which deal with inputs for discrete events.
现在,让我们添加跳跃功能吧,我们的运动和相机控制步骤使用了轴映射,他们处理这类控制所需的连续输入。这里还有处理离散事件输入的动作映射。
Map a discrete button or key press to a &friendly name& that will later be bound to event-driven behavior. The end effect is that pressing (and/or releasing) a key, mouse button, or keypad button directly triggers some game behavior.
一个离散按键映射到一个&friendly name& 后将会绑定到事件驱动行为。它导致的结果是,点击(释放)按键、鼠标键或者键盘按键(key)会直接触发一些游戏行为。
Let's add a new action mapping called Jump in the editor.
让我们在编辑器添加一个Jump动作映射。
1. In the Edit menu, click on Project Settings.
打开Project Setting.
2. Under the Engine heading on the left side of the Project Settings tab, click on Input.
选择Input.
3. Under Bindings, click on the plus sign next to Action Mappings.
在Action Mappings旁边点击加号。
4. Click on the arrow to the left of Action Mappings to expand the Action Mappings settings.
点击小箭头扩展动作映射的设置。
5. Type &Jump& in the text field.
输入文本。&Jump&
6. Expand the dropdown, and select Space Bar.
下拉选择Space Bar。
7. Close the Project Settings menu.
关闭Project Settings。
Now we want to bind this action to some code that will cause our character to jump.
现在我么想将动作绑定到可以控制角色跳跃的代码。
If we look at Character.h, we can see there is jump support built in, tied to the bPressedJump variable. So all we need to do is set that flag to 1 when the jump action is pressed, and 0 when it is released. We need two functions to accomplish this.
在Character.h中,我们可以看到Jump已被内置,它绑定在bPressedJump变量。所以我们要做的是在跳跃键按下设置为1,释放按键设置为0。这需要两个方法来完成。
1. In FPSCharacter.h, add the following public function declarations:
在FPSCharacter.h,添加如下方法声明。
//sets jump flag when key is pressed
UFUNCTION()
void OnStartJump();
//clears jump flag when key is released
UFUNCTION()
void OnStopJump();
2. In FPSCharacter.cpp, we can implement them very simply:
在FPSCharacter.cpp,简单的实现它们。
void AFPSCharacter::OnStartJump()
bPressedJump =
void AFPSCharacter::OnStopJump()
bPressedJump =
Finally, we need to bind the Jump action to our new functions.
最后,我们需要绑定跳跃动作到我们的新方法中。
3. In&SetupPlayerInputComponent, add the following:
在SetupPlayerInputComponent中,添加以下代码:
InputComponent-&BindAction(&Jump&, IE_Pressed, this, &AFPSCharacter::OnStartJump);
InputComponent-&BindAction(&Jump&, IE_Released, this, &AFPSCharacter::OnStopJump);
Because we added new functions instead of just altering existing functions like in the previous step, we need to compile in Visual Studio instead of in the editor.
1. Close Unreal Editor.
3. After the build finishes, open Unreal Editor, and then open FPSProject.
编译方法照旧。
4. Click on the Play In button in the Level Editor Toolbar.
5. Press Spacebar to jump! You should now have a good set of starting movement controls, with WASD moving and strafing, camera control with the mouse, and jumping.
6. Press Escape to exit Play in Editor (PIE) mode.
点击Play。
按下空&#26684;键跳跃。到此为止,你会有WASD移动、鼠标控制相机和跳跃功能。
-----------------------------------------------------
4.10亲测可行。
--------------------------------------------------------------------------------------------------------------
Now let's give ourselves a body in the world. The Character class creates a SkeletalMeshComponent object for us by default, so all it needs to know is which SkeletalMesh asset to use. Let's make a Blueprint of our&FPSCharacter&class
so we can easily set this asset and manipulate any future components we might want to add. We'll start by importing a third person Skeletal Mesh. Eventually, we will set it up so that there is one mesh that the player sees, and one mesh that other players
would see in a multiplayer mode.
现在,让我们在虚拟世界中给我们自己添加个身体吧。Character类默认为我们创建了一个SkeletalMeshComponent对象,所以只需知道的是去使用哪种SkeletalMesh资源。让我们为FPSCHaracter类创建一个蓝图,从而让我们可以轻松的设置资源以及操作以后我们想添加的任何组件。
1. Download the following zip file, and unzip it to get the third person mesh file.
下载下面的ZIP文件,解压活得第三人称mesh文件(获取FBX文件)。
2. Open Unreal Editor.
打开虚幻编辑器。
3. Right-click in the Content Browser, and select&Import to /Game&in the menu that appears.
在Content Browser中右键选择Import to /Game&。
4. Navigate to wherever you saved the FBX file, then select it and click Open.
选择你的FBX后点击打开。
5. Open the&Advanced&dropdown and check&Import Materials, then click on&Import.
点击Advanced下拉,勾选Import Materials,。(博主在4.10版本是直接拖拽FBX到Content的,跳出窗口默认选择,然后import.)
6. Click on the&Save&icon in the&Content Browser&to save your new Skeletal Mesh and its associated assets.
在&Content Browser点击Save图标来保存你新建的Skeletal
Mesh,它会关联资源。
Now, we can create a Blueprint of our FPSCharacter class and assign this new Skeletal Mesh to the SkeletalMeshComponent.
现在,我们可以创建FPSCharacter类的蓝图,指定新建的SkeletalMesh到SkeletalMeshComponent。
1. Right-click in the&Content Browser&and select&New Folder. Name this new folder&Blueprints.
在Content Browser&新建名为Blueprints的文件夹。
2. Double-click on the folder to open it.
双击打开文件夹。
3. Click on the&New&dropdown, and select&Blueprint.
点击New,选择Blueprint。(也可以右键选择)
4. Expand the&Custom Class&dropdown, and type &FPSCharacter& into the search box.
扩展开Custom Class,搜索FPSCharacter。(PS:4.10 的是叫做All Classes)
5. Click on&FPSCharacter&to select it as the parent class for your new Blueprint and then click on Select.
选择FPSCharacter作为新建蓝图的基类,点击Select.
6. Name this new Blueprint&BP_FPSCharacter, then double-click its icon to open it.
蓝图命名为BP_FPSCharacter,双击打开。
The Blueprint Editor will open in Components Mode, so we will be able to easily set our third-person mesh.
蓝图编辑器会以组件模式打开,你可以轻而易举的看到第三人称mesh.(PS:4.10打开蓝图可在左侧上部看到,如下图)
1. Click on the Mesh component in the Components tab.
在component选项卡中点击Mesh组件。
2. In the Details tab, scroll down to the Mesh section. Click on the dropdown that says None, then select your recently imported Skeletal Mesh asset. You may have to resize the Details tab to see this menu.
在Details选项卡,下滑到Mesh部分它显示none.点击下;希腊选择你新导入的Skeletal Mesh资源。你可能需要调整Details 选项卡来看到这个菜单(PS:这里应该是指……还是用图来说明吧,见下图)。
3. Align the SkeletalMeshComponent to the CapsuleComponent by setting its Z location to -88 in the&Details&tab.
在选项卡中通过设置它的Z&#20540;为-88来使SkeletalMeshComponent对齐CapsuleComponent(胶囊体)。
When using your own Skeletal Mesh assets, you may need to adjust them differently, but the overall goal is always to have the mesh contained within the CapsuleComponent, and facing the same direction that the ArrowComponent is pointing. This will ensure that
your Character moves correctly through the world. You can also move components around with widgets in the Preview Viewport, rather than setting values in the Details tab.
使用你资源时,你可能需要不同程度上的调整它们,但整体上始终是要包含在CapsuleComponent里面的的,并且面向方向与相同ArrowComponent 。这将确保你的角色在世界中正确移动。你也可以在Viewport中通过坐标移动components,而不仅是在Details选项卡中设置&#20540;。
4. Compile and save your Blueprint, then close the&Blueprint Editor.
编译并保存你的蓝图,然后关闭。
Now we need to tell our GameMode to use our Blueprint class for the player pawn, instead of the FPSCharacter class we set earlier.
现在我们需要告诉我们的GameMode为玩家pawn使用我们的蓝图类,使其替代早先我们设置的FPSCharacter类。
1. Switch to Visual Studio.
切换到VS。
2. Go to the FPSGameMode constructor in FPSGameMode.cpp, and replace the existing DefaultPawnClass assignment:
进入&FPSGameMode.cpp中的FPSGameMode构造函数,替换DefaultPawnClass的&#20540;。
DefaultPawnClass = AFPSCharacter::StaticClass();
with the following code:
使用以下代码:
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder&APawn& PlayerPawnObject(TEXT(&Pawn'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter_C'&));
if (PlayerPawnObject.Class&!= NULL)
DefaultPawnClass = PlayerPawnObject.C
This code will find the class generated by your blueprint and assign it as your default pawn class. (Note the &_C& suffix in the asset path, this is what distinguishes the actual class used by the game from the Blueprint asset, which is an editor-only concept.)
At this point, you could also remove the #include &FPSCharacter.h& from the top of FPSGameMode.cpp, since you are no longer referring to the FPSCharacter C&#43;&#43; class.
这些代码会找到你的蓝图产生的类,并使其成为默认的pawn类。(注意资源路径中带“_C”的后缀,这是游戏实际使用的类与蓝图资源之间唯一编辑器原则的区别,PS:这里不大懂。),同时,你也可以在FPSGameMode.cpp顶部移除#include &FPSCharacter.h&&(PS:可以注释掉),因为你不再需要关联FPSCharacter类了。
Note that if you put your Blueprint in a different folder in the asset tree, you can get the full path by right-clicking on it in the Content Browser and selecting &Copy Reference&. The full path will be placed on your clipboard for handy pasting.
注意:如果你把你的蓝图放在了不同的资源文件夹中,你可在内容浏览器右键选择获取完整路径。完整路径将放置在方便粘贴的剪贴板中。
1. Switch back to Unreal Editor, and click on the Compile button.
2. The Compiling C&#43;&#43; Code notification will pop up in the bottom right of the screen. Wait for it to finish - it will say Compile Complete and then fade out.
3. Click on the Play In button in the Level Editor Toolbar. If you move the camera around, you should be able to see your character's shadow.
4. Press&Shift&#43;F1&to regain your mouse cursor, then click on&Eject&in
the toolbar. You are no longer possessing the character, so you can move the camera around freely and see your character's mesh.
5. Click on&Stop&to exit Play in Editor (PIE) mode.
如果你移动摄像机,你会看到你的角色阴影。
按住Shift&#43;F1&,显示鼠标光标,点击工具栏上的Eject。你不在占有角色,所以你可以自由一定相机看到你的角色mesh。
--------------------------
4.10版本已测试成功。
--------------------------------------------------------------------------------------------------------------
At the end of the previous step, the default camera is positioned inside the mesh's neck. Let's set up a proper camera that we can use to adjust the camera's properties such as location and field of view. We're going to do this by adding a CameraComponent to
our FPSCharacter. First, let's add a property to the FPSCharacter to hold a reference to our CameraComponent.
在前面步骤的后面,默认相机是定位在mesh的脖子部位的。让咱设置一个适当的相机,我们可以用它调整相机的位置和视野等属性。
1. Go to&FPSCharacter.h&in Visual Studio and add the following to create a public property:
在&FPSCharacter.h添加以下代码:
/** First person camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
UCameraComponent* FirstPersonCameraC
We will also need to add a constructor to our&FPSCharacter.h&file.
我们需要为&FPSCharacter.h添加构造函数。
// Constructor for AFPSCharacter
AFPSCharacter(const FObjectInitializer& ObjectInitializer);
We will create the actual component in the FPSCharacter constructor.
我们将在FPSCharacter构造函数创建实际组件。
2. Add the following code in FPSCharacter.cpp to create the CameraComponent and attach it to the CapsuleComponent.
在FPSCharacter.cpp&中添加以下代码来创建&CameraComponent,并附加到CapsuleComponent。
AFPSCharacter::AFPSCharacter(const FObjectInitializer& ObjectInitializer)
&: Super(ObjectInitializer)
// Create a CameraComponent
FirstPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject&UCameraComponent&(this, TEXT(&FirstPersonCamera&));
FirstPersonCameraComponent-&AttachParent = CapsuleC
Finally, let's adjust the camera's position to be a little above the character's eye location.
最后,调整相机位置到角色&#30524;睛位置。
3. Add this to the constructor, after the component is created. You can tweak the camera's position in the&BP_FPSCharacterBlueprint later as well, but this gives a good starting location for the CameraComponent. Also, you will only set the
CameraComponent's location, not its rotation, because our earlier Turn and LookUp functions will control the camera's orientation.
当组件创建之后,添加下面代码到构造函数中。你之后也可以在中调整相机位置,但这里为CameraComponent给出一个好的出事位置。同样,你也可仅设置CameraComponent的位置量,而不是旋转量,因为早先我们的Turn和LookUp方法会控制相机的方向。
// Position the camera a bit above the eyes
FirstPersonCameraComponent-&RelativeLocation = FVector(0, 0, 50.0f &#43; BaseEyeHeight);
// Allow the pawn to control rotation.
FirstPersonCameraComponent-&bUsePawnControlRotation =
Because we added a new property, we need to compile in Visual Studio instead of in the editor.
因为我们添加了新的属性,我们需要在VS中编译。
1. Close Unreal Editor.
3. After the build finishes, open Unreal Editor, and then open&FPSProject.
4. Click on the Play In button in the Level Editor Toolbar.
编译如之前所述。运行。(4.10直接编译)
5. Your camera should be above the character's head now, and if you look down, you will be able to see the top of your character's head.
现在你的相机会在角色的头顶上,如果你想下看,你会看到角色的头顶。
6. Press&Escape&to exit Play in Editor (PIE) mode.
A common FPS approach is to use 2 separate meshes. One is the normal full-body mesh, used when seeing the character from third person but hidden when in first person. The second is a &weapon and hands& mesh that is attached to the camera and is visible only
to the player when the player is in a first person perspective.
通常FPS设置了2个独立的mesh.一种是全身mesh,在第三人称看到角色时被用到,第一人称时隐藏。第二种是绑定在相机的“武器和手”,当玩家处于第一人称视角时可见。
To implement this, we'll keep the existing component named Mesh as our third person mesh and make a new&SkeletalMeshComponent&to be our first person mesh.
为了实现它,我们会保留现有的名为Mesh的第三人称mesh组件,新建一个SkeletalMeshComponent作为第一人称mesh.
1. First add a public variable to&FPSCharacter.h&to keep a reference to this new mesh:
首先为FPSCharacter.h添加新的public变量来关联新的mesh.
/** Pawn mesh: 1st person view ( seen only by self) */
UPROPERTY(VisibleDefaultsOnly, Category=Mesh)
USkeletalMeshComponent* FirstPersonMesh;
2. Then, in the constructor for FPSCharacter.cpp, we'll add code to create and configure this mesh after our code that configures the FirstPersonCameraComponent:
然后,在的构造函数中,于配置FirstPersonCameraComponent的后面,添加代码创建并配置这个mesh。
// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
FirstPersonMesh = ObjectInitializer.CreateDefaultSubobject&USkeletalMeshComponent&(this, TEXT(&FirstPersonMesh&));
FirstPersonMesh-&SetOnlyOwnerSee(true);
// only the owning player will see this mesh
FirstPersonMesh-&AttachParent = FirstPersonCameraComponent;
FirstPersonMesh-&bCastDynamicShadow = false;
FirstPersonMesh-&CastShadow = false;
We are using&SetOnlyOwnerSee&here to indicate that this mesh is only visible to the &owning& player, in this case the PlayerController
who has possessed this Character. We also set the mesh to be attached to the camera. Finally, we disable some environmental shadowing since seeing shadows of these camera-attached arms would look odd and destroy the illusion.
这里我们使用来声明这个mesh是仅对玩家拥有着可见的,这种情况下,&PlayerController占有Character。我们同样把mesh附加到相机上。最后,我们关掉环境阴影,因为与相机连接的手臂的阴影看起来会不和谐。
3. Finally, we have to change the settings for Mesh, the existing third person SkeletalMeshComponent. Add the following lines to the constructor to set its visibility so it is hidden from the owning player.
最后,我们需要为Mesh改变设置——已存的第三人称SkeletalMeshComponent。在构造函数中添加以下代码来设置它的可见性,所以他会对所属玩家隐藏。
// everyone but the owner can see the regular body mesh
Mesh-&SetOwnerNoSee(true);
As before, we will set the mesh asset in the Blueprint, so let's compile and run the editor.
如之前一样,我们会在蓝图中设置mesh,所以编译运行编辑器吧。
1. Close Unreal Editor.
关闭虚幻编辑器(4.10省略该步骤)
3. After the build finishes, open Unreal Editor, and then open&FPSProject.
完成编译后,打开FPSProject(4,10省略该步骤)
4. Download this zip file and unzip it to receive the first person mesh FBX file, which contains a SkeletalMesh with just arms.
下载你解压ZIP文件获得第一人称mesh FBX文件,它只有手臂的&SkeletalMesh 。
5. Navigate to the&Game&folder in the&Content Browser.
到内容浏览器中的Game文件夹。
6. Right-click in the&Content Browser, and select&Import to /Game&in the menu that appears.
右键点击Content Browser选择&Import to /Game。
7. Navigate to wherever you saved the FBX file, then select it and click&Open.
进入你FBX所在的文件夹,选择并点击打开。(4.10可直接拖拽FBX)
8. Open the&Advanced&dropdown and make sure&Import Materials&is checked, then click on Import.
打开Advance下拉,确保勾选Import Materials&,点击import.
If you receive an error about smoothing groups, you can disregard it. This mesh will still work to illustrate the first person mesh setup, and will work with the animations set up in a later step.
你可以忽略遇到的有关平滑组的错误。这个mesh依然仍然有用,用来说明第一人称mesh的设置,以及后面步骤中的动画设置。
1. Click on&Save&in the&Content Browser&to save your new Skeletal Mesh and its associated assets.
点击Save&保存你的Skeletal Mesh,它会关联资源。
2. Navigate back to the&Blueprints&folder in the&Content Browser.
回到Content Browser中的Blueprints文件夹。
3. Open&BP_FPSCharacter&and switch to&Components Mode.
打开BP_FPSCharacter&,切换到Components Mode。(4.10直接打开就行了)
(NOTE: There is an additional step required as a workaround to an current issue we are looking into. To be able to find the FirstPersonMesh in the component list, you will need to delete the BP_FPSCharacter blueprint and recreate it. After doing this
you can continue with step 4.)
(注意:我们在这里使用了一个额外的步骤解决当前我么正在调查的问题。为了能在component列表中找到FirstPersonMesh,你需要删除BP_FPSCharacter蓝图重建它。之后你可以继续步骤4.)PS :4.10不需重建蓝图,已测试。
4. Find the new&FirstPersonMesh&we added. Notice that it is a child of the&FirstPersonCameraComponent, so it will always be attached to the camera. You may have to expand the FirstPersonCameraComponent dropdown.
找到我们添加的FirstPersonMesh,注意他是FirstPersonCameraComponent的子类,因此它会始终附着于相机。你可能需要打开FirstPersonCameraComponent扩展。
You may encounter an issue where the new&FirstPersonMesh&and&FirstPersonCameraComponent&do not appear in your blueprint. If this happens to you, you can remove the blueprint BP_FPSCharacter and create it again as described
above, and the new properties will appear.
你可能会在蓝图中找不到FirstPersonMesh&和&FirstPersonCameraComponent。如果是这样,你可以如上面说的移除并重建BP_FPSCharacter蓝图,这样它们就会出现了。
5. Click on the&FirstPersonMesh&component in the&Components&tab.
在&Components选项卡中点击FirstPersonMesh。
6. In the&Details&tab, scroll down to the&Mesh&section. Click on the dropdown that says&None, then select your recently imported Skeletal Mesh asset. You may have to resize the&Details&tab
to see this menu. Now, the arms should appear in the&Viewport, although you may have to zoom out to see them.
在Details选项卡中,下滑到&Mesh部分。点击None选择新导入的Skeletal
Mesh。你可能需要调整Details的大小来找到这个选项。现在,手臂会出现在Viewport,虽然你可能需要缩小才能看到它们的。(PS:感觉应该是放大吧)PS:博主在这里手臂没出来,于是关掉了蓝图,在虚幻编辑器编译一下,重新打开蓝图就出现了。
7. To adjust the relative transform so the arms appear on the camera, set the Location to {240,0,35} and the Rotation to {-180, 50, -180}. You will readjust this position after the arms are animated, but for now, this position lets you see that you are using
this first person mesh when playing.
为了调整相关的位置使手臂出现在相机的面前,设置Location为&{240,0,35},Rotation为&{-180, 50, -180}。当手臂动起来的后你需要重新调整位置。但是现在,这个位置让你看到了游戏运行时,你正在使用第一人称mesh.
8.&Compile&and&Save&your Blueprint, then close the&Blueprint Editor.
编译,保存,关闭蓝图。
9. Click on the&Play In button&in the Level Editor Toolbar.
10. At this point, you will no longer be able to see the third person SkeletalMesh, but you will be able to see the disembodied arms of the first person SkeletalMesh.
这里,你在也无法看到第三人称SkeletalMesh,但你能看到第一人称的虚拟手臂SkeletalMesh。
11. Press&Shift&#43;F1&to regain your mouse cursor, then click on&Eject&in the toolbar. You are no longer possessing the character, so you can move the camera around freely and see both the third person and the first person meshes.
按下Shift&#43;F1&重现鼠标光标,点击Eject,你不再占据角色,依次你可以自由移动相机,同时看到第一人称和第三人称的mesh.
12. Press&Escape&to exit Play in Editor (PIE) mode.
-----------------------------------------
4.10测试成功。
--------------------------------------------------------------------------------------------------------------
Now that the character is set up, let's implement a simple projectile weapon - when you fire, a simple grenade-like projectile will shoot from the center of the screen and fly until it hits the world. While we have the editor open, let's add an input and create
a new code class for our projectile.
既然角色已经建立起来,那么让咱实现简单的子弹发射吧。当你开火时,会有简单的类&#20284;子弹的东西从屏幕射击知道与世界中的物体碰撞。打开编辑器,为我们的子弹添加输入和代码类。
1. In the Edit menu, click on&Project Settings.
进入Project Settings。
2. Under the Engine heading on the left side of the&Project Settings&tab, click on&Input.
进入Input选项。
3. Under&Bindings, click on the&&#43;&next to&Action Mappings.
点击Action Mappings旁边的&#43;。
4. Click on the arrow to the left of&Action Mappings&to expand the Action Mappings settings.
点击Action Mappings左边的扩展箭头
5. Type &Fire& in the text field.
输入文本&Fire&。
6. Expand the dropdown, and select&Left Mouse&Button.
下拉选择&Left Mouse&Button。
7. Close the Project Settings menu.
关闭Project Settings。
Now let's create the projectile class.
现在,让我们创建子弹类。
1. Go to&File & Add Code to Project.
2. Choose&Actor, then click&Next.
选择Actor类,点击下一步。
3. Name your new class&FPSProjectile, then click on Create.
类名命名为FPSProjectile,点击Create。
4. Click on Yes to open the class in Visual Studio for editing.
点击Yes在VS中打开类。
5. Visual Studio will prompt you asking to reload the project, since the C&#43;&#43; Class Wizard modified it. Select Reload.
VS会提示是否重新加载项目,因为C&#43;&#43;类向导修改了他。选择reload.
First, we should decide on a simplified physical representation to use for collision and simulation. For our case, let's use a USphereComponent.
首先,我们决定简化用于碰撞和仿真的物理表示。在我们的案例中,我们使用USphereComponent.
1. Add a reference to this component in your FPSProjectile class declaration in FPSProjectile.h.
在&FPSProjectile.h的&FPSProjectile声明中添加组件引用。
/** Sphere collision component */
UPROPERTY(VisibleDefaultsOnly, Category=Projectile)
USphereComponent* CollisionComp;
2. Add a constructor to&FPSProjectile.h.
在FPSProjectile.h添加构造函数声明。
AFPSProjectile(const FObjectInitializer& ObjectInitializer);
3. Create the component in the FPSProjectile constructor in FPSProjectile.cpp. We'll make it the root component since the simulation will drive it, and we can attach visual components to it later in a Blueprint.
在FPSProjectile构造函数中创建组件。由于simulation驱使它的需要,我们将它设为根组件,然后我们可以在之后的蓝图中将可视化组件附件到它上面。
AFPSProjectile::AFPSProjectile(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
// Use a sphere as a simple collision representation
CollisionComp = ObjectInitializer.CreateDefaultSubobject&USphereComponent&(this, TEXT(&SphereComp&));
CollisionComp-&InitSphereRadius(<span class="nu17" style="color:#8f);
RootComponent = CollisionComp;
UE4 comes with a ProjectileMovementComponent that can be used to easily do simple ballistic-style movement, so let's add that to FPSProjectile.
UE4有一个可以做简单弹道运动的ProjectileMovementComponent ,因此我们将它添加给FPSProjectile.
1. First, add a public reference in your FPSProjectile class declaration in FPSProjectile.h.
首先,在FPSProjectile类声明中,添加public 相关变量。
/** Projectile movement component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Movement)
UProjectileMovementComponent* ProjectileMovement;
2. Then, add the following lines to the FPSProjectile constructor in FPSProjectile.cpp to create this component:
然后,在FPSProjectile.cpp的构造函数中添加以下代码来创建组件。
// Use a ProjectileMovementComponent to govern this projectile'

我要回帖

更多关于 大惊小怪造句 的文章

 

随机推荐