Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In this video, we're going to implement something very exciting, which is the character's main projectile.
In the end, we're going to have different types of projectiles.
So we have to think ahead a little bit and we're going to set up the projectile.
Keeping that in mind, in this video, in the lesson where we imported our assets, we also imported
the Flipbooks for our shots so we can go to paper assets FPS.
And here we have the player shot which is the regular player shot.
We have the player shot charge which is a charge shot.
And we have the player shot hit, which is the animation that plays if we hit a wall or an enemy, just
to show that the projectile explodes.
We didn't set up the frames per second for this.
So let's just take care of this right now.
Let's start on the right side with player shot.
Hit.
Open up the flipbook.
And this looks kind of fine.
It should just be an explosion.
But I want to make it a little bit slower.
So 13 fps is the value that I like.
And we can skip this and then go back to.
Next up is the player shot charge.
Just open this up and it looks a little bit fast.
So maybe this one as well.
We can go to 13.
Make it a little bit slower and a little bit smoother.
Then on to the next.
The player shot.
Which is a regular shot that we will use most.
And again, this one looks very fast, so this 1st May be around nine fps.
I think you can see switching between the frames better.
It looks more interesting.
And onto the next one, which is the fireball.
This is the projectile that the lizard will use, and it is the same as the player.
So we can just set it to nine as well to give it a uniform look.
And lastly we have the explosion.
This is what we're going to play.
If an enemy dies.
And this one again it looks a little bit fast.
So again here we can go to 13.
It should be kind of snappy.
And I think this looks about right and safe.
Okay, so this is all we need for setting up the settings on our flipbooks.
Now let's get into making the actual projectile.
And like I said before, we want to think ahead with this and make sure that we create a system that
allows for multiple projectile types so we can reuse functions and variables without having to make
every single projectile from scratch.
And again, our friend inheritance, which we already used for the character, the player and the enemies
comes in handy here because again, this allows us to set some basic variables, some basic functions
on the projectile base and pass everything down to the player projectiles to the enemy projectiles,
and then also have different types of player projectiles without having to code everything from scratch
every single time.
And again, this is something that is a little bit hard to plan out if you're a beginner, but it is
very important and you're going to get used to this over time.
First, we want to create the BP projectile base, and this simply inherits from the base actor, which
is the simplest type of object that can be placed in the world.
And we want to share parameters settings like the flipbook settings and things like that.
Downward, the base will also have collisions and events because we need to understand what our projectile
hits something and then have the projectile explode, apply damage.
And this is the same for all of our different projectiles.
We're going to have a flipbook in the projectile.
And most importantly we're going to have the projectile movement component.
And this is kind of similar to the character movement component we had with the character that handles
character movement.
But this is specifically for projectiles.
So we don't just have to go into the actor and code all of this from scratch.
The projectile movement already gives us a system that works, and we can just reuse that from Unreal
Engine.
Again, we also want to have a variable for faction, so we can make sure that a projectile that an
enemy shoots doesn't hurt other enemies, but only hurts the player.
We're also going to have a variable for projectile damage, and we're going to have a visual effect
when the projectile hits the wall and explodes.
The one we looked at before the flipbook.
And later on we're also going to add a sound effect.
And these are all things we're going to add over time as we need them.
And we're then going to split into two different projectile types.
So again these are only parents.
That's why I called them base.
We're not going to actually use them in the game.
These are just going to be used to manage our different children.
So in the player projectile things that are unique to the player that the enemy doesn't need is a system
that makes the projectiles disappear when leaving the screen.
In these Mega man type of games, usually you can only have three active projectiles at a time, so
you cannot keep on mashing the shoot button.
But the closer you are to the edge of the screen, the faster you can actually shoot.
So this system is nice for managing risk and reward.
And the way we're going to implement this is through a shot energy management system.
We're going to start out with a shot energy of three.
This means we can shoot three times and recover one energy every time a projectile is destroyed.
And that is a nice way of managing this.
And we're then going to have three different types of projectiles on the player.
And they all inherit these properties that we set here and here, of course.
And for the regular projectile, we don't have to change anything.
It's just going to be the default damage of one and just have this flipbook playing.
We have a partially charged shot.
This is if you hold the button and you let go before you get the full charge.
Here, we could change the damage.
I think some Megaman games have it where it does two damage, but I don't think it's necessary.
This should just look a little bit different so we can actually just change the tint.
We're still going to use the same flipbook, but in the settings we're just going to change the tint
to just show this as the partial charge shot.
And lastly, and most importantly, we're going to implement the fully charged projectile.
And here we're going to use a different flipbook.
So we can just overwrite the flipbook setting on the parent.
And we're also going to change the damage from 1 to 3.
And again we don't have to redo any of this from scratch.
Right.
We just have everything in here.
We pass it on.
We pass it down.
Instead of making three completely different projectiles and having to redo the same thing over and
over again.
And for the enemy, the projectile enemy base actually doesn't have anything in it that is different
from this one.
So this is literally just for management.
And later on we might decide that we have other projectiles again, and maybe we want to have something
in here.
And even though we don't really make use of the enemy projectile, it is good practice to have it here
because there's a high chance we're going to split off later on and make multiple other projectiles.
And again, for the enemy projectile lizard, we're just going to change the flipbook to this red one.
And we might have to change the damage depending on how much damage we want the lizard to deal.
And this is the overview of the projectiles.
And I hope this wasn't overwhelming.
Of course, these are things you kind of figure out as you make the game, but it is nice to kind of
think about it beforehand and plan ahead so you don't drive yourself into a corner and have to redo
code again and again.
In this video, though, we're only going to create the projectile base.
We're going to create a the player projectile base and the BP player projectile regular.
All of the other ones are going to come in later chapters.
Okay.
Let's now create the base projectile so we can go to Content blueprints.
Make a new folder called projectiles.
In here, we again want to have another folder called player and another one called enemy.
But here in the projectiles folder right click create a new blueprint class of type actor.
As we discussed, because it's the simplest type that you can have.
Click here and call it Bpy.
Underscore.
Projectile.
Underscore.
Base and caps.
And hit enter.
And from this, let's create all of the children we need for this video.
So here we can just right click Create Child Blueprint class.
And we're going to create the BP player projectile.
Base.
And we can drag this into the player folder.
Move here.
Go in here as well.
And from this one right click again Create Child Blueprint class.
And here we'll have the BP player projectile regular.
And if we look back at our graph, right, we just created the BP projectile base, the BP player projectile
base and the BP player projectile regular.
And now when we implement something we need to be careful in the end decide which one we need to pick.
So first we want to work on the general base.
So back in the projectiles open up the BP projectile base which is the highest layer in our inheritance.
Double click to open it up.
And we can just drag this here.
And again, this is just a regular blueprint.
We have the viewport.
We have the event graph.
There's nothing fancy going on here.
And now we're just going to implement the functionality we want all projectiles to have, no matter
if it's player projectiles or enemy projectiles.
The first thing we want to have for a projectile is at the projectile.
Movement component and just put it here.
And this is what is going to make our projectile move forward, which is going to affect gravity and
do all of these things.
Again, this is something that Unreal Engine or Epic Games made for us, because this is a very common
thing in most games that people need.
So there's no point in just making this again and again from scratch by yourself.
In a later step, we're going to look at all of the details and the things we can set here.
The projectile movement component needs a collision to work though, so we can go to add.
And in our case we want to use a sphere collision.
You could also use a box collision and others but it depends on your use case.
But in this case sphere collision is the best.
And very important.
This needs to be the root.
Now it is a child of the default scene root, but the projectile movement component will use the root
for the collision.
So we have to drag it here.
And now you see the default root disappeared.
And this is now the highest in our hierarchy.
And this is what we need to have for the projectile movement to work, because it only accounts for
the most upper level of collision.
But this still doesn't look like a projectile for us.
So if we select a sphere, we want to add a flip book, a paper flip book, right?
And if we have the selected on the right side for source flip books, now we can just look for shot
or shoot.
And we want to use the player shoot loop.
And this is our most basic projectile.
And since the sphere will handle all of our collision, we don't want the paper flip book to have any
collision.
So we can just go to the details.
And on the right side we set it from block all dynamic to no collision, because we don't want the actual
flip book to collide with things.
And this could lead to bugs and weird behavior.
And now we also want to talk about the material settings on this paper flip book, because you remember
that on the player to make things look more real, if we start the game, we have the shadow on the
player and we have the player cast shadows.
And here you have to decide what your personal preference is.
But since these projectiles are energy or some plasma, I don't think we should set them to masked lit
sprite material because it would be weird for them to receive shadows, in my opinion.
And I also don't want them to cast shadows, so I don't think we have to change anything here.
We can just leave it at masked unlit and we don't want it to cast shadows.
Next, we want to think about the size of the sphere so you can see that the sphere is bigger than the
paper flipbook, and we can just go to sphere and drag here to make it smaller.
And we could make it match perfectly.
But actually that is usually not what you want to do.
And this is a little bit of game design knowledge.
And I set it back to 32, usually for projectiles or things that the player uses.
Because you want to make the player feel good, you should usually make the collision a little bit bigger
than what it looks like.
So even if the player misses a little bit, it would still hit and the player feels rewarded.
What is a really bad practice for a player would be to make it smaller, so that even though it looks
like it should have hit, it didn't hit.
And that is something that makes players angry and makes them feel like your game isn't fair.
So for this again, again, I think 32 is the best value because we are a little bit bigger than the
paper flipbook.
And on the flip side, for enemies, you usually want to make the collision a little bit smaller than
what it should look like to give the player a little bit of leeway.
Now let's drag this projectile into the world and see how it behaves.
So we can just drag it in here.
And if you want to test something like this, we don't care about the player right now.
So instead of just going in here and worrying about the player.
A simpler way to test this is to just click here and go to simulate.
Right?
So now we can just start the game without spawning a player.
It's easier for us to test and see what happens here.
And what happens here now is that there is gravity on the projectile and it just falls downward, which
is not what we want, but we can easily set this up.
So in the projectile base on the projectile movement component, we can just look for gravity and set
this to zero because we don't want gravity to affect our projectile.
So now if we just simulate it's just staying in place which is already good.
But we of course want the projectile to fly forward.
And for this we have two variables here.
We have the initial speed and the max speed.
And again I was playing around with these values a little bit.
And I found that 1000 feels about right.
And for both of these we want to use 1000.
And you can then see how the projectile flies.
Forward.
And yeah, this is how it works.
So the projectile movement component makes the projectile fly forward.
And this is it very simple, very easy to set up.
Now we want to set it up so that if the projectile hits a wall it's going to be destroyed.
To do this, we can simply select the floor.
So yeah, make sure you have the floor selected.
We can hold alt on the keyboard, and we can drag here to create a copy of the floor.
We can then go into rotation mode and rotate it up like this 90 degrees.
And this just gives us a nice wall we can use for testing.
And if I simulate now you're going to see that the projectile just passes through.
It ignores the wall.
And this is where collision channels come into play.
And this is also a somewhat complicated topic, which I'll try to sum up in simple terms for you.
There is actually a great blog post which I'm going to attach to the lecture, which you can check out
if you want to get some more in-depth knowledge about this, but we're just gonna go over it quickly.
So basically we can set a collision response to either ignore overlap or block.
And we have different types of world static, which is the walls, the floor.
We have a world dynamic which would be our projectile by default, which are other things that just
move in the world.
We have pawn, which is our character, but actually we can also create our own channels here, which
we're going to do for the projectile.
So we can define which items should overlap with the projectile, which items should block the projectile
and which items should just ignore it.
And what does ignore, overlap and block even mean?
Let's just imagine that this character is the projectile in this sense, and if the projectile hits
this bush, an overlap event will be triggered.
And if we set the projectile to overlap with bushes and the bush to overlap with projectiles, if the
projectile flies in here and overlap event will be triggered.
And we can then decide what we're going to do here.
You could, for example, just have the projectile keep on flying and maybe just have the bush start
burning, for example.
And this would be a perfect case for an overlap event.
But you could also just say that the projectile hits the bush, and the bush maybe doesn't do anything,
but the projectile is supposed to disappear.
And again, this is also something we can do with an overlap event.
A hit event, on the other hand, means that if two hard objects collide with each other, even if we
don't do anything on the event, both of the objects will block each other anyway.
This means that even though the projectile can pass through the bush, if it hits the wall which is
blocking, it is just going to either stick to the wall or like hit the wall and fall down.
In this case, we will also trigger an event.
So we could then, for example, use the information in the event to see where did the bullet hit and
maybe spawn like a bullet hole in the wall.
So there are good use cases for both overlap and hit.
And the way I want to set it up for this game is that our projectile will hit the wall so they will
block each other.
But let's say this bush is an enemy for the enemies.
I just want to use an overlap event so the projectile hits the enemies and we can then decide are we
going to let the projectile pass through, or are we going to destroy it?
Like, what are we going to do?
And I believe this is the cleanest setup for our game.
So what can we do now to make sure that this projectile will be blocked by the wall?
We can first of all check the floor or wall and look to the collision settings.
And in here we see block all dynamic.
And if we open this up, you see that it blocks pretty much everything, which is cool.
And this itself, the object type is also world dynamic.
So this is not world static.
This is also world dynamics.
So we need to make sure that the projectile also blocks world dynamic.
Because even if the wall tries to block the projectile but the projectile ignores the wall, the ignore
state will win.
They both have to block each other for the blocking to take effect.
So in the projectile base, we can go to the sphere here and scroll down to the collision settings.
And here you can see overlap all dynamic right.
So here we see well the wall was a world dynamic.
And here we only overlap the world dynamic.
But in our case we actually want to block the world dynamics.
So what could we do here.
Well we could go here and for example select block all dynamic.
And now also here we just block everything and we can go back here and simulate.
And you can see that we get stuck in the wall.
So this is the behavior we want to have in this case.
And we achieved this simply by changing the collision preset.
We could then take this one step further and again, while you have the sphere selected on the right
side, keep on scrolling down to the on component hit event.
So this is the event that triggers if two blocking objects hit each other.
On the other hand, we have the on component begin overlap.
This triggers if two overlapping objects pass through each other and we have the end overlap.
And this is if you leave the overlap area.
But in this case, again because they are both blocking each other, we can use the on component hit
event here and just click on plus.
And we could then, for example, just print.
Print string here and get the other actor.
And this is just going to show the name of the actor that the bullet hits.
And we can just start here.
And on the top left you see floor two, which is correct, right?
This floor two is what we hit.
So we can get some information here.
And we could then we'll exit out here.
And we could then use this information.
Right.
So we get the hit event which is huge.
So we can break this for example.
Right.
So we can get the blocking at the time distance location.
So many things you can do with this.
But our game is very simple.
So we aren't going to use this.
We're also not going to use the other actor.
Well everything we have to do is that if we understand that we as the projectile got blocked, we simply
have to destroy the projectile at this point in time.
So just destroy actor.
Compile, save and let's do this.
So the bullet comes flying, it hits the wall and it disappears.
So this is the first step of what we want to achieve.
And later on we of course want to again on the sphere.
We want to set it so that we don't block all dynamic, but we only overlap with the pawn with the other
enemies, so we can then apply damage to them into other things.
But that is a topic for a different video.
So what we did here, we achieved that.
A projectile flies, it hits the wall and it disappears.
And in the next lesson we want to show a particle effect that shows the bullet exploding before we destroy
it.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.