Welcome back.
In this video we're going to find out how to fix this pesky little problem with our firebolts.
Sometimes they don't explode.
Now what happens is, if we're launching a Firebolt at an enemy, and that enemy just happens to die
before the Firebolt gets there, while the Firebolt still homes in on its homing target, which is now
gone.
Let me show you what I mean.
There we go.
So the enemy died and the Firebolt floats there.
And after the enemy sort of perishes.
Look at that.
There's really no homing target for it to go to, and that's annoying.
Now there's a fix to this.
We can fix it in tick.
Wait, wait, wait a minute.
Did Stephen just say tick?
Isn't that bad practice.
Tick is always bad practice, right?
Well, not if you can set the tick rate to a low value so an actor doesn't take very often.
Let's go into ability, system or abilities.
Fire Firebolt and get our Firebolt.
Now an actor that ticks less often is a lot more performant.
And if we have Firebolt self selected right here, we have a tick interval.
Now if it's set to zero well that's going to be the maximum.
And let's just see what that looks like by drawing a debug sphere at its location we're going to get
actor location.
And I'm going to promote this to a variable called location this frame.
And I'm going to set that in tick.
And I'm going to use that to draw a debug sphere with a radius of five.
It's going to be white and its duration can be five seconds.
So let's see how often that tick looks like.
That's a whole lot of spheres, right?
Now, if we set our tick rate, which is this tick interval here to 0.1, that's ten times per second.
That's a lot less than 60 or 120.
Modern computers these days it's 120.
So ten times per second is not often at all.
Let's check it out now.
See, that's a lot less.
And we could even put this down even more to say 0.2.
That's five times per second.
I mean, that's not very long now.
My point is that we can use tech and we can see if that fireball has stopped moving.
That's the approach I'd like to take.
So I'm going to take that draw debug sphere, set it off to the side.
We're going to set location this frame.
But I'm also going to promote that get actor location to a variable and call this one.
This will be the location last frame.
So location last frame.
And I'm going to set location last frame equal to.
Location this frame before updating.
Location this frame like that.
And now we have this frame and last frame we can see the difference between them.
So I'm going to take location this frame subtract location last frame.
And we can get the vector length of this.
And that will tell us how far apart these locations are.
So if we get a vector length we can check it.
And we can have a minimum we can have a threshold.
So let's go ahead and make a variable called min distance per frame.
This can be a float.
We can compile.
And we can set this to a low value like ten.
And we can check if this vector length is less than or equal to min distance per frame.
If that is the case, well, let's do a branch and decide what happens.
What I'd like is for the projectile to go kaboom.
So spawn sound at location at and let's just see what our impact sound is here.
It's this sound effect right here.
So I'm going to set that the location we have location this frame and then spawn system at location.
And again, I want to see what impact effect we have here.
It's this one.
And actually we have to we're not using this one.
So if we use this one we could change it up a little bit, change how it looks and then we'll know for
sure if that is what is being spawned.
So we'll do that at location this frame.
Like so.
And then we'll destroy the actor.
Okay, now this explosion, I'm going to just change a bit.
You can uncheck these emitters to change what it looks like.
I'm just going to change it.
So it just does one little thing.
Perhaps just the ring.
And maybe the sparks black.
That's pretty different.
So I'm going to save that.
And now with our fix in place let's see what happens.
And we definitely saw them explode.
See, it hovered for a second and then it exploded, which actually looks pretty cool.
See?
Hover, explode and that little hover for a second.
Of course, you can change the tick interval to a smaller value, but 0.2 is fine.
It's only five times per frame.
That is not that much at all.
And of course all of this is something that could be moved into C plus plus as well.
It's not going to be that much more performant.
I'm just going to collapse it.
To a function and call this make go kaboom.
And we'll do that in event tech.
We'll say make go kaboom if no move.
Make go kaboom if no move.
Perfectly descriptive.
Right?
Perfectly.
All right.
So that takes care of that issue.
And of course, you don't have to play the weird little black tar looking explosion.
You can play the regular explosion.
Boom boom.
Awesome.
So yeah, we don't have to play that weird explosion.
We can play our impact effect.
So I'm just going to browse to that and use that system.
And with that we have a very nice performant solution.
I'll see you in the next video.