欢迎回来 Welcome back.
在上一个视频中 我们下载了这个级别 这样我们就可以有一些更令人愉快的东西 In the previous video, we downloaded this level so we can have something a little bit more pleasing
在我们开发的过程中查看 to look at while we're developing.
所以我要找到我们的球员开始 So I'm going to find our player start.
当我被选中的时候 我必须专注于它 我将继续删除这个 When I was selected and had f to focus on it, and I'm going to go ahead and just delete this one.
我们将要找到一个好的 安静的地方 我们可以繁殖我们的角色 所以我找到了这个小地方 And we're going to find a nice, quiet area that we can spawn our character, and so I found this little
办公区和我决定把球员明星放在这里 office area and I decided to place the players star here.
所以一旦我们开始比赛 我们就有了这个区域 还有一些周围的噪音 所以我继续 So once we start playing, we'll have this area and there's still some ambient noise, so I went ahead
停止录制桌面音频 这样你就可以听到我的声音 不用担心 and stopped recording the desktop audio so that you can just hear my voice and you don't have to worry
关于噪音 about the noise.
但现在 这将是一个很好的地方 让我们在抗议时繁殖 好的 所以在这个视频中 我们 But for now, this will be a nice place for us to spawn when protesting, OK, so in this video we're
准备实施自动射击 going to implement automatic fire.
因此 当我们按住触发器时 即鼠标左键或控制台上的右触发器 So when we press and hold the trigger, which is the left mouse button or the right trigger on the console
控制器 controller.
我们要像自动武器一样快速射击多次 而不是一次射击 Rather than shooting once, we're going to want to shoot many times very rapidly like an automatic weapon
可以 would do.
要做到这一点 我们将利用计时器 To do that, we're going to make use of timers.
让我们开始吧 Let's get started.
这里是射击角色Don H 我将向下滚动到我们的私人部分 Here we are in shooter character Don H and I'm going to scroll down to the private section where we
可以添加一些私有变量 can add some private variables.
在下面的底部 我想要一个布尔值 当我们的消防按钮被按下时 Down here at the bottom, I'm going to want a boolean for when our fire button is being pressed.
所以我要写一本书 叫做《按下点火按钮》 So I'm going to create a book called B Fire Button Pressed.
请发表评论 For the comment.
我会说鼠标左键或写 I'll say left mouse button or write.
控制台触发器按下 Console trigger pressed.
现在 我还将创建一个名为“确定火”的布尔值 这将是一个 Now, I'm also going to create a boolean called Be Sure-fire, and this will be a boolean that will
用来知道我们是否应该开枪 use to know whether or not we should be firing a bullet.
换句话说 一旦我们发射了一颗子弹 我们就会启动计时器 In other words, as soon as we fired a bullet, we're going to start a timer.
在计时器持续时间内 我们不应该开枪 And during the duration of that timer, we should not be firing a bullet.
但一旦计时器结束 我们就可以将这个球设置回真 这样我们就可以再次开火 But as soon as the timer is over, we can set this ball back to true so that we can fire again.
所以当我们可以开火时 我们会说是真的 So we'll say true when we can fire.
等待计时器时为False False when waiting for the timer.
现在我们想知道我们想多久发射一次武器 所以我们要创建一个名为 Now we want to know how often we'd like to fire the weapon, so we're going to create a float called
自动射击速度 这将告诉我们每发子弹之间应该经过多少秒 automatic fire rate and this will tell us how many seconds should pass in between each bullet fire.
所以我们要说的是自动射击的速度 So we're going to say rates of automatic gunfire.
最后 因为我们使用计时器 我们将创造足够的时间来处理 我们将调用 And finally, because we're using timers, we're going to create enough time to handle and we'll call
这是自动点火计时器 this auto fire timer.
至于评论 我们会说在枪声之间设置一个计时器 And for the comment, we'll say sets a timer between gunshots.
现在我们要创建一些函数 这些函数将设置这个按布尔键的火灾按钮 我们将 Now we're going to want to create functions that will set this fire button pressed boolean and we're
我要把这些绑在消防按钮上 going to bind these to the fire button.
所以 让我们创建“按下消防按钮”和“释放消防按钮”功能 我们将在 So let's create fire button pressed and fire button released functions and we'll stick these up in the
受保护部分 protected section.
第一个按钮将被按下 The first one will be void fire button pressed.
下一个将是无效的 消防员被释放 And the next will be void, firemen released.
这些函数名是不言自明的 所以我不打算给出这些注释 These function names are self-explanatory, so I'm not going to give these comments.
让我们为这些创建函数体 Let's create function bodies for these.
当智慧创造第二个智慧时 它总是要思考 Intelligence always has to think when it creates the second one.
好的 我们有函数定义 这些只是简单地设置Boolean B fire按钮 OK, so we have the function definitions and these are simply going to set the Boolean B fire button
按下消防按钮为true 按下B 按下消防按钮为false pressed to true for fire button pressed and B, fire button pressed to false.
对于释放的消防按钮 现在我们可以向下设置玩家输入组件 我们可以 For fire button released and now we can go down to set up player input component and we can take our
开火按钮 查找动作 函数 调用 我们将调用 fire button, find action, function, call, and instead of calling fire weapon, we're going to call
按下点火按钮 fire button pressed.
因此 现在按下鼠标左键或控制台上的触发器不再导致射击武器 So now pressing the left mouse button or the trigger on the console no longer results in fire weapon
调用后 现在我们只需将此布尔值设置为true being called, now we're simply setting this boolean to true.
所以我们必须用另一种方式来处理武器的发射 So we're going to have to handle firing the weapon in a different way.
我们将复制这个函数 调用并粘贴它 We're going to copy this function, call and paste it.
我们将使用IHI released 而不是IHI pressed And instead of IHI pressed, we're going to use IHI released.
我们将调用fire 当按钮被释放时释放 And we're going to call fire and released when the button is released.
好的 我们将要设置计时器 所以我们希望有一个可以启动计时器的函数 OK, so we're going to be setting timers, so we'd like to have a function that can start the timer,
让我们创建一个名为start fire timer的空函数 so let's create a void function called start fire timer.
我们还需要一个函数 在计时器完成时调用它 我们 And we're also going to want a function that gets called when the timer is complete for this, we're
将创建一个名为void auto fire reset的函数 going to create a function called void auto fire reset.
因为它将是计时器的回调 所以它需要是一个新函数 And because it's going to be a callback for a timer, it needs to be a new function.
那么 让我们也为它们创建实体 So let's create bodies for these as well.
现在对于自动点火重置 我们要做的就是将B设置为true Now for Auto Fire reset, all we're going to do is set B should fire to true.
现在 B应该开火是我们要检查的金块 看看如果 Now, B should fire is the bullion we're going to check to see if we should be firing the weapon if
这是假的 it's false.
我们不会开火 We will not fire.
这就是它现在的工作原理 So here's how it's going to work now.
一旦我们启动点火计时器 我们就要检查是否应该点火 As soon as we call Start Fire timer, we're going to check to see if we should fire.
所以如果我们开火 So if we should fire.
如果我们能开火 我们就称之为火力武器 If we can fire, we're going to call fire weapon.
这会考虑到武器的实际发射 That takes care of the actual firing of the weapon.
现在 一旦我们发射了武器 我们就把“确定”设定为“假” Now, as soon as we fired the weapon, we set be sure fire to false.
现在 我们不能再开火了 Now, we can't fire anymore.
现在 既然我们要发射武器 我们就要启动计时器 Now, since we're firing the weapon, we're going to start the timer.
所以我们称之为世界计时器管理器 So we're going to call it world timer manager.
调用set timer函数 我们将传递一个自动点火计时器 And call the set timer function and we're going to pass an auto fire timer.
我们将把它放在自己的线上 We'll put that on its own line.
接下来 我们通过这个 Next, we pass in this.
正如我们通过第六次重载函数可以看到的 接下来是整个对象 As we can see by going to our sixth overload of the function, which takes the entire object, next
是函数回调 我们将从中使用shooter字符 is the function callback from which we're going to use a shooter character.
好极了 Hotto.
消防复位 最后 延迟时间 这将是自动火灾率 Fire reset, finally, the delay time, which will be automatic fire rate.
现在我们要在fire button pressed函数中调用start fire timer 这里是fire button Now we're going to call start fire timer in the fire button pressed function, so here in fire button
按下 我们不仅将“点火”按钮设置为“真” 还将调用“启动点火计时器” pressed, not only are we setting fire button pressed to true, we're also calling start fire timer
也 as well.
到目前为止 按下按钮调用启动点火计时器 它检查我们是否应该点火 B是否应该点火 So far, button pressed calls start fire timer, which checks to see if we should fire, if B should
火是真的 我们发射武器并设置B应该发射为假 fire is true, we fire the weapon and set B should fire to false.
然后我们启动计时器 直到B应该再次触发为真 我们才能再次触发 Then we start the timer and we can't fire again until B should fire is true again.
所以 如果我们在计时器结束前按下点火按钮 我们将调用启动点火计时器 So if we press fire button pressed before the timer is over, we'll call start fire timer.
但启动消防计时器无法进入室内 But start fire timer will not make it inside.
B现在应该开火了 B should fire now.
定时器一完成 我们就调用自动点火重置 该重置将点火设置为真 As soon as the timer is done we call auto fire reset which sets should fire to true.
但一旦调用自动点火重置 我们应该检查是否仍在按点火按钮 But as soon as auto fire reset gets called, we should check to see if we're still pressing the fire
按钮 所以我们可以说 如果按下消防按钮 如果我们仍然按住消防按钮 我们 button so we can say if the fire button pressed and if we're still holding the fire button down, we
可以重新启动消防计时器 can start fire timer all over again.
因此 调用启动火灾计时器 So call start fire timer.
因此 如果我们继续按消防按钮 一旦定时器完成自动消防重置 我们将进行检查 So if we continue to press the fire button, as soon as the timer finishes auto fire reset, we'll check
看看我们是否还在施压 to see if we're still pressing.
如果是的话 我们会重新启动消防计时器 If we are, we'll start the fire timer all over again.
所以我们现在继续开火 And so we'll continue to fire now.
自动火灾率需要有一个值 Automatic fire rate needs to have a value.
让我们转到构造函数 So let's go up to the constructor.
在这里的初始化或列表中 让我们为它添加一个初始化 我们将从 And up here in the initialise or list, let's add an initialization for it and we'll start it off with
零点一秒四点一秒 我们将对此进行评论 zero point one F four point one seconds and we'll comment this.
现在自动射击 记住这一点 一秒钟需要更大 Automatic gunfire right now, something to keep in mind this point, one seconds needs to be a larger
值大于十字光标排列插值的计时器速率 value than the timer rate for interpolating for the crosshairs spread.
我们需要足够的时间让十字准星在枪声之间展开和收缩 We need enough time between gunfire shots for the crosshairs to spread and shrink back.
记住 十字准线扩展计时器使用零点零五 这是该值的一半 And remember, the crosshairs spread timer uses zero point zero five, which is half of this value.
一旦我们发射十字准星 开始向外扩散4.05秒 然后 So as soon as we fire the crosshairs, start spreading outward four point zero five seconds and then
开始向内收缩 begin to shrink back inward.
在那之后的一秒钟内 我们不会再发射另一颗子弹 And we won't fire another bullet for another point, one seconds after that.
所以请记住 如果你增加自动射击速度 你必须增加质询 So just keep in mind that if you increase automatic fire rate, you have to increase that interpellation
枪声扩散系数的时间或时间 time or time for the gunfire spread factor.
让我们来看看这里发生的一切 So let's take a look at everything that's going on here.
因此 首先发生的事情是我们按下鼠标左键或控制台触发器和点火按钮 So the first thing that happens is we press the left mouse button or the console trigger and fire button
按下 则被称为“按下火灾按钮” 将按下的布尔火灾按钮设置为true并调用start pressed, gets called fire button pressed, sets the boolean fire button pressed to true and calls start
消防计时器启动消防计时器将首先执行F检查 看我们是否应该开火 fire timer start fire timer will first perform an F check to see if we should fire.
如果检查成功 则调用fire武器发射实际武器 If we succeed in that check, then fire the actual weapon by calling fire weapon.
设置B应该触发为false 因为我们不能按我们想要的速度按下按钮 Set B should fire to false because we shouldn't be able to just press the button as fast as we want.
我们应该等消防计时器告诉我们可以再次开火 We should have to wait for the fire timer to tell us we can fire again.
我们也开始计时 We also start the timer.
这让计时器开始工作 我们必须等待由自动射击速度确定的秒数 This gets the timer going and we have to wait the number of seconds determined by automatic fire rate.
现在 一旦计时器完成 就会调用auto fire reset 因为它是的回调 Now, as soon as the timer finishes, then auto fire reset gets called because it's the callback for
计时器 the timer.
自动点火重置设置B应再次点火为真 然后检查点火按钮是否正确 Auto fire reset sets B should fire to true again and then performs a check to see if the fire button
现在还很紧张 is still pressed.
如果点火按钮仍然按下 那么我们再次调用启动点火计时器 它再次检查B是否应该 If the fire button is still held down, then we call start fire timer again, which again checks B should
开火 我们刚刚设置为真 自动开火重置 这意味着我们将再次开火 fire, which we just set to true an auto fire reset, which means we'll fire the weapon again.
设置B应为false并启动计时器 Set B should fire to false and start the timer.
一旦计时器结束 我们设置B应启动 以再次检查按钮是否仍被按下 Once the timer finishes, we set B should fire to try to again check to see if the button is still pressed
然后调用启动消防计时器 我们将无限期地继续这样做 直到我们松开消防按钮 and call start fire timer and we'll continue doing this indefinitely until we release the fire button,
这会导致调用释放的消防按钮 which causes fire button released to be called.
这会将按下的点火按钮设置为false And that sets B fire button pressed to false.
这意味着当在计时器结束时调用auto fire reset时 我们会检查是否有一个fire按钮 This means when auto fire reset gets called at the end of the timer, we check to see a fire button
按下是真的 它不会是真的 这意味着我们将停止调用启动射击计时器 武器将 pressed is true and it won't be, which means we'll stop calling start fire timer and the weapon will
停止射击 stop firing.
这就是我们设置自动火力的方式 So that's how we set up automatic fire.
现在 我们需要做的最后一件事是给出布尔值的默认值 Now, the last thing we need to do is give our booleans default values.
我们按下了点火按钮 应该点火了 We have fire button pressed and should fire.
现在 在我们初始化的底部的字符构造函数中 我们的列表将添加 Now, here in the character constructor up here at the bottom of our initialise, our list will add
我们应该开火 它的默认值应该为true we should fire and its default value should be true.
你没有理由不能在第一次按下按钮时就开始开火 但是要小心 There's no reason you shouldn't be able to start firing the first time you press the button, but be
默认情况下 按下的fire button应该为false 因为我们在按下按钮之前不会开始按下它 fire button pressed should be false by default because we don't start off pressing it until the button
被点击 gets clicked.
好吧 先考虑一下它自己的初始化列表部分 我们将更改注释 Well, go ahead and consider this its own section of the initialised list, and we'll change the comment
说自动火灾变量 to say automatic fire variables.
现在我们已经初始化了变量 让我们编译 我们回到ED 我继续 So now that we've initialized our variables, let's compile and we're back in the ED, I went ahead
然后打开桌面音频 这样我们就可以听到这些了 and turned on desktop audio so we can hear this.
我们要试试这个 We're going to give this a try.
我们有它 我们有自动火力 And there we have it, we have automatic fire.
总之 在本视频中 我们创建了自动开火所需的变量和函数 So to summarize, in this video, we created the variables and functions necessary for automatic fire.
在下一个视频中 我们将实现跳跃 并确保播放正确的动画 In the next video, we're going to implement jumping and make sure that we play the correct animations
通过在我们的动画蓝图中处理跳跃 for jumping by taking care of that in our animation blueprint.