Hello, this is Yeong-hoon Lee
This time, we are going to create collision and dynamic background scroll
First, we're going to learn about collision between actors
And ways to play the explosion VFX audio during collision
Also learn about UV animation to scroll the background
Collision effect
Continuing from last time, we are going to try collision effect
and background scroll effect
What we need to know about collision is that
When we make an actor
There's an event called ActorBeginOverlap
When there's a collision between two actors
This is the event that occurs
We're going to use this to process it
But the problem is
If we process it in the same place, there may be issues
If you look at the structure, the things that appear
There's the enemy and there's the bullet
And there's the player
If we process it all in the same place, it's a little difficult
We can't process it in the player
Because the collision between the Enemy and the Bullet is occurring between these two
Then look
The Bullet and the Enemy collide like this
The Enemy and the Player can collide
So let's form a relationship
So the Player stays still
The Enemy gets processed when it's the Player
And the Bullet gets processed when it's the Enemy
To put it again, when the Enemy and the Player comes across
We're going to make a collision effect
And when the Bullet comes across with the Enemy
We'll make another collision effect
That's how we will format it
Let's try the Enemy first
Then come to BP_Enemy, it's a little messy here
Should we go like this?
It will be better if we format it like this
Then the things we look at for collision is here
Let's make it simple first
Let's process it for the instance when the Enemy and the Player collides
When processing these in Unreal
Collision is ultimately two objects running into each other
Even if multiple things collide at once
The actual things that collide are A and B, or B and C
A and C, so the collision of two things
That's what we're trying to process
So here, this is what we're going to
The Enemy, a.k.a me, I'm the Enemy. I collided with the Player
And we both die
So to collide, we can basically
Process it using ActorBeginOverlap
Look, then it the opponent is the Player, we can process it
Other Actor is the Player
Ways to prove this exist in many ways
Whether the tag is correct, whether the tag is there
Or if the name contains the word "Player"
Or there's the concept of casting
In the language perspective
We have the concept of parent-child class
There's the parent class and the child class
Then when the child class inherits the parent class
We make the object and change it into a parent type
Or change it into another type
This is casting, also known as type conversion
And if the casting succeeds
It becomes their child
So if the Other Actor is BP_Player
For BP_Player, in the upper right hand corner, the parent class is pawn
But pawn eventually inherits the Actor
So here, if we take this Actor
And succeed in casting into a Player, it becomes the Player
And we can bring it like this
Let's try casting, type cast
Cast BP_Player and try type conversion
It may or may not succeed
If it fails, it's not the Player
If succeeded, or if failed
If succeeded, the casted or type-converted object
Pops out this way
Other Actor transforms into this
Then if it succeeds, what happens?
You die, and I also die
So we'rer going to destroy the opponent first, then destroy myself
Then the Other Actor may destroy with this
Or destroy the guy casted with BP_Player
Ways to destroy is simple. Just pull it over like this
And type Destroy Actor
This way, the target is the opponent, or the Player
It's the Player, so it means destroy the Player
And to destroy myself as well
Select Destroy Actor for me as well
Now the target here is "self"
This means destroying myself, when this is called out
If you look here, there's EndPlay, just like BeginPlay
That node gets called out
If we need to add more things afterward, that's where we'll work
Let's keep this flow
Should we see if it works?
Let's compile and play
Place this in the middle, and let's try colliding
It doesn't collide
There are a couple of possible reasons, let's take a look
If you look at the Enemy, in order for collision to occur
In order for this Overlap event to occur, we need to set certain things
What it is, is there's a cube here
If you look at the cube, it says Static Mesh Components
Static Mesh Component means
When an objects is drawn out 3D, Mesh is needed
The Mesh is used for drawing
On the details of the right side, it says Static Mesh and there's a cube
There's an outer appearance like this and the material
This material gets colored into the Mesh
That's why it looks white
Then when you look under the Static Mesh
there's also something called Collision
This talks about how it's going to collide
If you look at Collision Presets
It says BlockAllDynamic here
This means that only Block is possible
See here? Block
But what's our event here?
BeginOverlap, it needs to Overlap
But now it's only in Block
So we need to process it as Overlap
And now, for this BP_Enemy
The Object Type is in WorldDynamic
In WorldDynamic, it's only processed as a Block
Here, there's Ignore, Overlap, and Block
Ignore literally means ignoring, so no collision
Overlap is the concept of overlapping
Block is colliding and pushing it away
So this is actually colliding
Overlap is recognizing it
But here, only the collision is checked off
That's why Overlap isn't working, so let's change it
Right now, we have the Enemy and the Player. Should we look at the Player too?
If you look at the cube of the Player, the settings are like this
This also only allows Block
So we can do this right away, but to make it more accurate
We're not using the collider within the object
It's better to set a separate collider
Let's do that
Should we do it for the Enemy first?
In the Components part of the Enemy, press the Add button
Scroll down
Then there's the menu called Collision
There's box, capsule, sphere
We're in the box form right now
So click the BoxCollision and create it here
Take this, and see where it says DefaultSceneRoot?
We're going to put it in here, it won't go in at once
So do this, Attach, then do it again
Put it like this, and the DefaultSceneRoot becomes a box
Like this, set it so that the collider becomes the Root
The Components structure of Unreal generally works like this
If there's the Actor
The Root composes the Actor
There are Root Components
Under that, there are other Components
There may be even more Components under this one
Or it may be under here, that's the general structure
The very top is the Root Component
So normally, the collider is set as the Root Component
That way, there's income
Those will work normally
That's why it should be set like this
We'll talk about that later again
For now, we'll set it simply like this
Then if you look at the Viewport, it looks like this
For the box, if you look at the upper right detail
There's something called Box Extent
This is half the size of the box
It says 32, so it will be 64 cm
But the outer look we're using right now
This cube is 1 m big
So let's increase the size of the box to 50
50, 50, 50, and when you look at the edge
You can see the brown line here
If we increase it to 52
you can see that the collider is this big
To fix it to the same size, set it to 50, 50, 50
Then the horizontal, vertical, and the length becomes 100, 100, 100
Let's do this job for all 3 areas
For the Player as well
Add BoxCollision
Insert the Collision into DefaultSceneRoot
And set the Box Extent to 50, 50, 50
Same thing for the Bullet
Let's do the same job
It will be better to click here
Then BoxCollision, then it will add onto here
Then insert it
The size for this is a little different, right?
So we're going to do it a little differently
The cube is shifted a little to the side
Let's set this to 0
That's why it drifted towards the right earlier
Do this, and see how it looks like this right now?
We'll control this a little
Do 50, 50, 50 for now
If you look here, the x for the cube is 0.75
You just need to multiply that here, multiply 0.75
Multiply it, and the size fits automatically
Was it 0.25 earlier? Yeah 0.25
Multiply 0.25 to the y value of 50 and it fits perfectly
The size is adjusted, and now compile
Now we added all 3 colliders
Now we need to process it
After this, we need to set the collision
Also, the existing cube has a collider
So we need to set it so that it doesn't get used as the collider
Select the cube, let's start from the Enemy
Select the cube of the Enemy, scroll down to the Collision part
We're not going to use this as the collider
So select NoCollision
Let's do the same job for Bullet and Player
In the Collision part of the cube, select NoCollision
Same thing for the Player
Like this
Cube, NoCollision
That's how we'll process it
Then, we're going to make the box collide
After making the box, it says Overlap
OverlapAllDynamic, right?
You can keep this as is
It's all set as Overlap
Later, we are going to create the Object Type
And set the collision relationship between the Object Types
We won't do that now
We'll try it when producing with C
For now, let's set the simple collision setting
After this, compile, and play it again
Now you can see it actually colliding
Come to Enemy, and you can see the ActorBeginOverlap is working properly
Then now that we've collided here
We just need to process it, right?
Should we do it here too?
As we've planned before
We said collision between Enemy and Player
And we also said Bullet and Enemy
So we'll do this too
Go to Bullet, go to the Event Graph of the Bullet
There's ActorBeginOverlap here too
We'll do the same job here
Here, if the collided Other, or the opponent is
Enemy
Then you die, and I die
So we're going to Cast here as well
Cast to BP_Enemy, the Bullet and the Enemy
So the opponent tried casting
They casted Enemy, and it was correct
Then you die, I die
Then Destroy Actor here
Duplicate this and connect it all the way
Then they both get destroyed
Let's see the results
Yes it works
Then colliding with the Player works
And colliding with the Bullet also works
And it's too boring when we just collide
So we'll make the explosion effect
And also play some sounds
Should we start with the Enemy first?
Collide with the Player, you die and I die, then after that
We're going to express the explosion effect here
For the explosion effect
If you look at the StarterContent, there's something called Particles
There's P_Explosion here, and this is what we'll use
This is the effect that explodes
We'll process it so that it appears here
When we were making the bullet
When you look at the Player making the Bullet
Where is it?
We used the SpawnActor node
It uses the name Spawn
That effect also uses the name Spawn
So we're going to use that
Unreal basically has the new effect system called Niagara
Also called the Particle System
And there's the existing legacy method's Particle System
It called Cascade
What we're going to use right now is
Here, it says Cascade Particle, right?
So we're going to load the VFX made by Cascade
And draw it out here
Let's try
We want to do you die, I die
We'll express the explosion effect in my (Enemy's) location
Right-click here, put Spawn
It's at the very top, it says Effects
There's Spawn Emitter at Location
We can also Attach, it's literally attaching
But we just need to use its location like this
So connect it like this
Then when you open up the template
There's P_Explosion here. We're going to click this and Spawn it
Then in the location part, we're going to decide
Where we're going to make it
It says 0, 0, 0 but it's not 0, 0, 0
We're going to express it in my current location
So put Get Actor Location
And connect it like this
Compile, play, and let's try colliding
What happens? You can see the exploding effect
Very simple, right? That's how we process it
We can leave it like this, but I think adding sound will be better
So we'll express some sound
Then we need something
Later, I'm going to provide it to you guys
For now, I'm going to use the sound file I have, it's an audio WAV file
In Unreal, sounds are produced through WAV files
So I've prepared two WAV files
This is the explosion sound, and this is the bullet firing sound
While we're on it, we'll also try the bullet firing sound
So when it explodes, which is about here
We'll play the sound here
Then we need to add the resource to our project first
Here, we'll make a folder here
New Folder, Sounds
Like this
And here, we're going to add the sound file
After this, drag it right away
Then the sound gets inserted
But this doesn't mean it becomes a file right away
If you look here in the folder, there's nothing
Right now, it only exists in the memory
So we need to save it through Save All
Then we finally get the file
In Unreal, for any type of file, the asset
For all assets, when we actually use it
Even if it's a WAV file
It goes in with the name uasset
So this becomes the form that contains the meta information
That's what we'll use
To listen to the sound, we can play it here
Hear it?
Those are the two sounds
So we're going to output the sound here
Then here, type Play Sound, and this pops up
There's 2D and there's at Location
This is the spacial sound
If you look at VR or games like Battleground
You can hear the footsteps in surrounding mode, like 3D
Is it 3D? They say 7.1 dimension
So for spacial sounds like that
Use at Location
But for 2D, like phone games
We can just use Play Sound 2D
We'll use this here
It's very simple, connect the play button here
Then here, we need to insert the audio resource we want to play
Here, it says Sound Bass, right?
Here, type Explosion, there's a couple of others
But let's add the one that we made
Was it this?
The name was Explosion, right?
We'll use this as is
Compile, play, and now you can hear the explosion sound
Do the same job for the Bullet as well
We can copy and paste the work here as well
Copy it, go to Bullet
Use Ctrl V to Paste, then connect it right away
Compile it
It works the same way
But for the Bullet, rather than exploding it at the location of the Bullet
I think it's better to make the Enemy get destroyed
So right now it's like this, but connect this to the opponent
For the Bullet, put it at the opponent's location
Let's change it to locate the VFX like this
Then play it
I think this looks more natural
But there can be errors
This is
The error happened here
This is because the destroyed thing
Location was used to draw it here
So it will be better to change the location
Cut this off, and go like this
At the very last, Destroy Actor
The first one is this
Drag it all the way here
Let's change it like this
The existing one here, let's move it to the back
Now there's no error, right?
Let's make the sound for bullet firing as well
Then when BP_Player does Fire
Spawn it, then play the audio here
Here, Play Sound 2D
After this, was it star-wars? star-wars-blast
Let's play it like this
But if you think the volume is too high
You can adjust the sound, if you look here
Hover the mouse on the center, this appears
Put it to the side, and a palm appears. Double-click there
Then this menu appears
There's volume here
It says 1 here, so change it to 0.1
We can reduce it by 1/10
We'll reduce the sound here
Then the sound becomes very quiet
That was about the collision process
Processing the Background Scroll
Then we'll try processing the background scroll
Then we need an image
I found this image on Google
We'll try using it, if you look here
It's just a picture of outer space
We're going to scroll this
In a way, we're putting the image on a roller and spinning it
Then a certain part will look like it keeps spinning
When we continue to scroll the image
That's how we'll process it
This process is called UV coordinate animation
For short, we just say UV animation
UV is, since long ago, the horizontal is U
And the vertical is V, right?
So if you look, what we call texture
There's an image here
In 2D, image is, as the name says, is called an image
Or Sprite
But in 3D, it's not called this way
This is called Map, or Texture
These are the terms
So usually for 3D, later you will
Learn it when you learn about graphics
But to explain it in simple terms
When we draw on a 3D space, there's a shape like this
What this shape is based off of, is a point
A point is something like this
Points in the 3D space is called vertex
In English, it's Vertex
Connect the two points, and we can make a line
In 2D, line is just a line
But in 3D, or the reality
If you look at an object in reality, such as milk box
If this is the milk box, this is the line, right?
But this ultimately is the edge, right?
So the line in the 3D space
is called Edge
And if there's another point, we can make a face
We can make a face
The face has multiple names
We can call it a Triangle
Or literally a Face
Or Surface or a Polygon
Polygon means a shape with multiple sides
The polygon that uses the least amount of points is a triangle
So we call it a polygon
Usually when we talk about Polygon, we're talking about a Triangle
So these Triangles are connected like this
If you see here, this is also a triangle
These are all triangles
This thing formed with triangles
is called the Mesh
It's called a Mesh
Then what Texture is
The image that covers the Mesh
Since Texture is actually a 2D image, it will look like this
Then on this Mesh, the Texture is
In a way, getting applied
You apply it and show it here
Usually when we apply it, the whole surface
Let's say there's image X
Then it gets applied like x, x, x
But if we express this as 0 and 1 here
Horizontally, then this is called U
And from here to here is called V
That's why it's called UV animation
Then here, it's 0 and 1 Then what's here? It would be 0.5
Here, it will be 0.1
The location here has its own information
And let's say we want to draw this part on this surface
And from here to here, we'll draw it here
We can also do that
This is called UV Map
So these are the things of UV
Ultimately, the way of processing this UV
Determines the various jobs we can perform
Especially, what we're trying to do right now is UV animation
The concept is very simple
For example, if we say that this is 0, 0
I can't remember exactly, if it's 0, 0 here
I think this was 0, 0
In 2D, the top left hand corner is 0, 0
But usually in 3D, the bottom left hand corner is 0, 0
So when we process it here, there's something called Offset
It's the concept of how far you're off from the center
If you continue to increase or decrease this offset value
It will roll, that's the concept
So by continuing to change this UV coordinate
The rolling can be processed
So that's what we'll do
When we process these, of course
The top edge and the bottom edge has to touch naturally
Because rolling means that this and this will touch
If we roll sideways
The left and right side will touch and spin
So I'm using this space background because it's easier
It's dark, so it won't look unnatural
So I've prepared this image
Then let's put this image here and process it
Let's make a folder
Call it Background
Here, we'll add the image
Same thing for this, we need to save it
Then if you look here, the shape
On the very bottom, there's the Plane
We'll bring this here
Plane, as the name says, it's a flat surface
Rotate it 90 degrees
We're going to use this as the background, and first put the location at 0, 0, 0
Then we'll move it back a little
Push it back a little
We'll increase the scale
Then when we click the camera, it looks white
Make it a good size
It just needs to fill up the camera, here there's some space
We'll have to increase it more
Fill it up all the way
Then here, we're going to insert the image
To make it accurate
If you look at the Plane, there's also Static Mesh here
And there's Material
We're putting the image into the Material part
Material is literally, the material, right?
We can add color to the material
Or insert an image on the material
These are the basic Materials they provide
Should we produce our own?
Usually, you can just drag and drop
Then it automatically makes one
But we'll make it ourselves
Right-click here, and there's Material
Make one like this, and name it M_Background
Usually, Material is shortened as MAT or M
Double-click to open
This is called the Material editor
Let's insert the image here
We add the image that we just brought in
There's Material here, but we can look into the details later on
We'll make it simple today
After this, connect the RGB part to Base Color
But when you do this, there's light here
Because the Material we're using right now is
Basically the physically-based shader
So they called it the Physically Based Shader
So we're going to, the sunlight here
Ignore the light of DirectionalLight
And express its own image color
So to do that
Click the floor here
Look at the details on the left side, and there's Domain
The Material Domain is in Surface, this is the flat face
This is the surface, but we'll change it into UI
User Interface, UI, usually
Doesn't receive lights like that
So change it into image that doesn't receive light
Connect this to Final Color, and you'll get this
Then we need to do the UV job
We're going to move the UV, and to process this, it's very complicated
So we're going to use Nodes, to be simple
There's a node called Panner
There's Panner here, and we'll connect the Panner like this
After that, let's enter a value of 1 into the speed value
Then it moves like this
I can see that it's moving sideways
After saving it, go to the game map
We'll insert the Material that we just made, into here
Like this, insert it here
Then you can see it move
Of course, it's moving sideways
But it looks like this because it's rotated
And the color smears a lot, right?
We need to process this, and this is called eye adaptation
What it is, is like when you suddenly go to a bright place and you can't see well
It starts off very bright, then your eyes adapt after time passes
This is the basic setting
That's why it's like this
So here, go to Project Settings
Search for Auto Exposure, and there's this
Uncheck this
Auto Exposure is automatic eye adaptation
So uncheck this
Go back, and there's less of that
And play it, and it's like this
But it's too fast Let's change the speed
Let's change this to 0.1 like this
Save and play, and it's much slower
Like this
That's how we can do it
Right now, it's a little messy here
The color too, I don't like it
We'll adjust the brightness a little
It's a little too bright
We'll Multiply the RGB part
Multiply is literally multiplying
Like this, connect it like this
Next, we need to multiply some value here
If you look here, we're going to make Emissive Power
Search for Scalar
There's something called Scalar Parameter
Click this and make one
Then, the value here is in Default Value, but make it into 0.2
Then we'll connect it like this
Then it becomes darker
We'll name it Emissive Power
Save it, play it, and it looks like this
I think I zoomed in too much
This is too big
So it's too
Let's shrink it a little
Like this, we can scroll the background
Processing it like this is called UV coordinate animation
So today, we've tried producing a shooting game that utilizes blueprints
We'll summarize the content learned today
Processing collision Processing collision between Actors Process the collision using the Event ActorBeginOverlap node Try casting using the Cast To BP_Player node
After creating the collider for the collision process, set the collider to the Root Component Set the Collision Presets setting of each Actor's Cube detail to NoCollision
Producing Explosion Effect during Collision Produce an explosion effect using the P_Explosion of Content StarterContent Particles
Create Spawn Emitter at Location node and Get Actor Location node and connect them to express particle effect at the wanted location
Producing the explosion effect audio Create a new Sounds folder in the Content folder and, move the WAV file, then save it as an asset
Create the Play Sound 2D node and add the Explosion file into the Sound category
Processing the Background Scroll Processing the background scroll Express the animation of continuous movement through UV coordinate animation Select Material in the Content Background folder
Create a new Material file, M_Background Connect the RGB output pin of Texture Sample node to the Final Color input pin of M_Background node
Create a Panner node and connect it to the UVs input pin of Texture Sample node Drag and drop M_Background into the Material category of the detail window
Disable the Auto Exposure by unchecking the box in the Project Settings window