Hello, this is Younghoon Lee
We're going to learn about bullet firing and the spawn system in this session
In this chapter
You will learn how to move bullet actor in C++
And how to Spawn bullet actor
According to the user's input
Also, you will learn how to play audio file in C++ as well
Bullet actor and moving it, Handing input, Firing
Let's build the bullet to begin with
Just like before
Create a new actor
From Tools in new C++ class
And I will name it BulletActor
BulletActor
The bullets will need a collision object and appearance as well
Let's repeat what we did
When we made the player
Go to bullet's header first
Let me declare the components in order to create
The collision object and appearance first
Write in UPROPERTY
And then EditAnywhere
Do a forward declaration
Write class UBoxComponent
And then BoxComp
And we need a component for appearance as well
UPROPERTY
EditAnywhere
Then, declare UStaticComponent, like this
I meant StaticMeshComponent
It's always better if you use the autocomplete
Write MeshComp
Now let's move on to
The source file
I'll do the same thing in the constructor
BoxComp
create DefaultSubobject UBoxComponent
Let me clarify again
components typically use U as a prefix
Like this
I will add BoxComp add here as well
And then I will set this as root component
SetRootComponent
Then we need to add header now
For convenience, I'll use this to work quickly
Add the header into UBoxComponent
Something's wrong here
Include BoxComponent into Components
So if you add like this we can set it to the root
Now we need to build the appearance
Let's create Mesh Component as well
Write create DefaultSubobject
For this, UStaticMeshComponent
Like so
Add TEXT here
The reason we put TEXT here is this
We can just put in without it
But
It can be a little complicated
This TEXT is
Let's look at it here
TEXT is formed like this
Like this
WIDETEXT or UTF8TEXT it's formed like this
So if you look here, the format
It's very complicated right?
Basically, the Unreal Engine uses
Unicode format of UTF16
But When you set up a network
Or import or export other files
Handling such tasks
Is called encoding
You need to do some encoding there
Especially in C++
Encoding can often be confusing and cause some frustration
However in Unreal Engine
You can use this macro to use automatic features
What this means is that
Deciding which platform to build this on
Or which method to make each system files
So, when you handle such task
You can be assisted by the text autocomplete feature
For encoding purposes
So this is what TEXT macro is for
Therefore, try using text macro
To wrap the text string as needed
Now here, this need to be rooted as well
Let's attach MeshComp to BoxComp
And then SetupAttachment
Next, you can choose between Box Component and Root Component
Box Component will become root anyway
So either of them have the same pointer value
So you can handle it the either way
We've built our gun
Appearance needs to be adjusted also
But we cannot quite do it just yet
We don't know what value to put in
For the scale and so on
So we should look what we've got
In the Unreal Engine before we do anything with it
Since we made our BulletActor
Let's make the actor into blueprint first
Now, let's name it BP BulletActor
We will create it in the blueprint folder
Things are not in place because I didn't compile it
So, let's go ahead and compile it
Make sure you save all before compiling
So, save it like this
Now let's compile again
Then you can see it working well
This default root isn't supposed to be there
But the setting doesn't always get applied correctly
If this happens, just try turning it off and on again
Sometimes even that wouldn't fix the problem
In that case, do you see the class setting here?
You can change the parent class here
Or you can also find it in the File tab as well
Reparent Blueprint is what we are looking for
They are the same menu
So just change the actor
And then change it back to Bullet Actor
You will see it working well
Sometimes, in cases like this, it can be quite confusing
With everything breaking apart, links being invisible and whatnot
For example, when you chose mesh
But details wouldn't show up
Even with the proper settings
In that case, blueprint must be broken
You can try making blueprint again
You can also change the parent and then change it back again
So you can fix it the way you see fit
But this method is better
So, Let's change its parent and then change back again
Now let's insert appearance into mesh component
Search for cube
Make one 1 cubic meter big
Compile it
And basic shape material for appearance
And then we need to do what we've done for the blueprint
Since the red one is the front
Let's have it face forward
Arrange your camera at a top view
And then reduce the size
0.75 and 0.25
set it up like this
Then resize the box to be 50x50x50
And then multiply 0.75 and 0.25
Now that the sizes have been set
Let's look at what we've done in the codes
Let's handle mesh component first
If you look at the mesh component, for the scale of the Transform
I set it to 0.75, 0.25, 1 so let's use that
Here, you can right click to copy it
So copy it, move it here
Paste it right here
Then it will look like this
I'll apply the scale of these values
To the mesh component
If you write Setscale here
You can see world scale or relative scale
You can choose between the two
Either relative
Or the world, it doesn't matter
Because we're not modifying the scale of the original itself
We're only adjusting the scale that's at the highest level
So, whether it's relative or world scale, they're essentially the same
For now, I'll approach it with the concept of relative scale
Finish the code like this
Now we need to make the vector here
FVector is what we need
Put it in the bracket like this
You can put the value in there
You can just input these values as they are
0.78 and 0.25
Like so
Next, if we look at the box
We also changed the Box Extent, right?
Let's we try copying this as well, like the 37.5 here
Copy it
This one is called Box Extent
If you come here to the BoxComponent
What I copied are gone
Let's go back and copy the value
Let's Paste it
There is a function called SetBoxExtent for the box component
We will paste the value here with FVector
Paste it here
So the value will be 37.5 and 12.5 then 50
Just like so
This is how you would handle it
So, first, let's visually inspect it in the Blueprint
After that, convert it to code
This is necessary because later on
For example, if you create an actor like this
But imagine if I delete this
And create it again from scratch
Then, if you had done this operation in Blueprint
If you made modifications to values here
And then deleted the Blueprint and recreated it
Those changes wouldn't be reflected
You'd need to reapply those values again
If you write it in the source file like this
When you create it anew, these values will be applied immediately
This would be more convenient, although it might be
Therefore, writing it like this here
Can be considered more desirable
So that's how we handle it
Now let's take it out
If you do that it will look like this
So now we need to make sure this to spawn
We will make it spawn
We have to do it here
Let's complete the characteristics of the bullets first
It will needs to be moving forward
Then, to make the bullet actor move forward
You can move it in the Tick function
Write I want to move forward
To implement the functionality
The direction is already set
Then we need how far
We want to make it move 10 meters per second
So, I will make variable called speed
UPROPERTY
Like this
And then
Write float Speed
Give the value of 1000 for this
So we can move it 10 meters per second
And then, come back to Tick
Let's actually move it
The formula for movement is
P equals P0 plus vt
This formula is used very often
So please keep in mind
While we're at it, let me clarify this
The formulas we often use are called physics formulas
When we actually develop games
The formula for motion
This is in a way
An uniform motion
Uniform motion with constant velocity
This is called Uniform motion
Formula for motion itself is basically about uniform motion
We also have acceleration
Formula for acceleration
Formula for motion is P equals P0 plus vt
For acceleration, oh these ones should be vector
Speed is v for velocity
So, v equals v0 plus at
This is the formula for acceleration
So current velocity is current velocity plus
Acceleration times by t
And then we have formula for force
so, F equals ma
So, force is mass times acceleration
If the value for mass is 1
Force is acceleration itself
So these are the formulas
The three basic formulas we often use
It's used a lot, knowingly or unknowingly
Next, vectors are widely used also
We learned about vector addition and subtraction
Through addition, we learned how to create a vector like this
When an object is bound by two vectors like this
And then we learned that if we have one vector here and another vector here
We can create a vector pointing in this direction
By subtracting vector b from vector a, resulting in vector c
And later on, you'll also learn about vector multiplication
Vectors are fundamentally characterized
By direction and magnitude
Direction is actually vector
So, there's vector multiplication for directions
And then there's scalar multiplication
Size is scalar
So, the multiplication of directions in vectors is called
The cross product, denoted by × and pronounced as cross
We call this the cross product
Also known as the outer product
And scalar multiplication is called the dot product, represented by a dot
So, we call it the dot product, which is also known as the inner product
You'll use these concepts quite frequently
Honestly, just grasping these concepts here
It should account for 30% to 40% of the work
So, rather than these concepts being very difficult
Of course, they can be challenging at first like this
Especially through concepts like vector multiplication
You can determine magnitude and angles
This can help you find the normal
It's not normalize, there is something called normal
There might be an opportunity to explain this later
but for now, it would be good if you could remember it this way
We're primarily focusing on
Learning about the formula for movement among these concepts
Let's give movement once again
Make P0 first
Start with FVector
For P0 find our actor's current position
GetActorLocation
Get the position
And then we will make velocity
First, we need to determine the direction
Write FVector dir
So, we said the direction is forward
So, when you use GetActor
With FVector like this
If it's the front, it's 1, 0, 0
But doing it this way means it's always in an absolute direction
Instead of that, for the relative forward direction
We use GetActorForwardVector
Then it means my front
Current actor's, my front side
Like so
And if you create a velocity in FVector here
Write V
And dir speed
So now, we can combine these
SetActorLocation
P0 plus v times DeltaTime
Now, it will go to the front side
Save now
You can use Ctrl Alt F11 for shorcut
These shortcuts were designed without considering Korean users
So in Korea, this shortcut appear differently
So, it's a bit inconvenient, but
Anyway, it ends up like this
So, you can just press this
If you look here
The shortcuts with their names are written at the top like this
It's okay to press like this
Sure, let's try arranging it
So, arrange it like this and rotate it like so
Let's see if it goes forward now
It goes up like this
If you look here, it's upwards like this, with the color red
You can see it going up
Now let's proceed to creating bullets
Not this
Now we need to proceed to creating bullets
To do that, let's go to the player
What I want to do here is this
If you press left mouse button
Write I want to spawn a bullet actor in the level
But we want to spawn them in a certain place
We want to Spawn
Write arrow
We've made this arrow thing last time
This arrow is at where ArrowComponent is
We want to use
Transform of the ArrowComponent
First we need to receive input
After that, we should be able to create it like this
Let's try
To recieve input
We've created a function like this
We've created the method
Just like that let's make one as void type
Write on and we will use action not axis
Let's wrap this one first
From Project Settings input
Let's add action mappings
I want to call it the Fire
And we'll handle the button as the left mouse button like this
We just made an action
called the Fire action
So let's name it OnActionFire
And now we need to implement the function
Press Alt Enter to implement the function
Let's create another function
That performs the action of making bullets when I press this Fire button
I'll call that function to create the bullets
I'll create a function like this, void MakeBullet
Create the implementation for this as awell
Now let's go this way, ActionFire
Now we need to register it
Register the function to this input
These ones
As before, you can use the BindAction function
In PlayerInputComponent for this
If you look at the contents here
You put name into the action
And then which key was pressed
What kind of action it is
What kind of event it is
And then the user class
We use This for this
And finally
It's out of the screen
This is it
So if you look at the third box
Let's reduce the size
If you look here, we need Ptr for the method
And then the pointer
Alright, so I'll write it like this
TEXT
Earlier, we mentioned Fire
So the name we put in here
Is the name we used there
Write it like this
Write Fire
The second part asks what action was taken
And here we can see there are basically three main options
One is whether it was pressed, released, or held down
Repeat means doing the action over again
Alright, we can categorize it as press, release, and so on
I will do this wen pressed
And then this and name of the function goes in
Like this
When we add this, always use &
To give away the function's address
So if we do this, it will become the call
Now it's connect
The concept is that
When I press the button, this function is called
Now let's go down a bit
Here we need to use Spawn
For Spawn we can use a function called getWorld
Look at world, you will find SpawnActor
Do you remember that when we did blueprint
We did this
Here, Spawn, Actor of Class
You remember using node like this?
You can consider these to be the same
Now, if you come here
You can use a function called SpawnActor
To create bullets we so desire
Then, here
This is built generically using a template
So add the pointed parentheses
Add ABulletActor here
Add that you are going to make BulletActor like this
And then what actually goes in here is
UClass
You've probably seen User class but UClass will be new
For UClass, think about what I said
If you take a look at this Uclass
When the Header tool executes
It analyses these actors
To make something called UClass
It means ultimately, Uclass is
Some kind of similar to actors
Actor, pawn characters for example
So, ones that we can create to utilize
So here it says such codes must be in here
So let's create an UClass here
Go to Player pawn header
Now to make a bullet actor
We need some kind of entity for the actor
Now we will make a documentation to contain the entity
Write UPROPERTY
Write EditAnywhere
Write down like this
And then let's start with UClass here
UClass pointer
Use the line trace
Let's name it the bullet Factory here
Like how bullets are made one by one in the factory
That's why I use the name bulletFactory
The reason why I say that is because
What do we need to do to make an item in the factory?
We call
Please send me a bullet
Then the worker will get up
And go to the factory to make a bullet
And then carry it in a car
To deliver the product
That means actual file input output operations will happen
Even if we just create it and use it directly
Actually reading a file
Loading it into memory
And using it is the core concept
So you need some time
So that's why I am using a term called factory
So for now we will use UClass Factory for the name
Then, after loading it into memory, you can proceed to write it like this here
I created a factory and arranged it like this
Then, the second parameter should be passed
As either transform or 1 of 7
So, this means there are now seven overloaded versions of this
So, this means there are seven versions of the SpawnActor function
Now, try pressing the down arrow key on your keyboard
The parameters look a bit different in this way
It seems like we can just use the transform here
We've decided to use arrow
To Arrow
Bring GetTransform
If you take a look, there are several things
We want to use the world coordinate system
But there isn't world written here
We have relative or socket
There is only component
This component is the world
One thing that's a bit disappointing is that the names
In the blueprint and the names here in C++ are a bit different
Some of them are different little by little
So, be careful for that case
When we talk of GetComponentTransform
It indicates the world coordinates of this arrow component
This is how we obtain the transform in the world coordinate system
That's that
The reason error occurs is
Because we haven't included the header
It's not recognizing UClass right now
So let's just add the header
Include it like this
Let me go ahead and add it like this
You can just write it like this
Works well right?
I think I placed it incorrectly
This one should go here
Calling the MakeBullet here should be better
The reason I did it like this is because
When I have some time
I wanted to try shooting automatically
So I separated MakeBullet like this
That's that
Next
We need the gun to shoot
let's go ahead in this direction and compile it
Save all
Compile it
Come to player
And look at Class Default
The Bullet Factory is empty
So right here
We want to place
The blueprint, BP BulletActor
And then if you open it
I only want to put the bullet in but there are so many other things
There are way too many stuff
These are all classes that inherit from UClass
Even Actors inherit from UClass
Because it's set up like this, it can be a bit difficult to find
You can just write it down
if you look, you will find BP BulletActor
You can insert like this
If you keep doing it like this every time
It will be very inconvenient for maintenance in the future
Because there's a risk of something incorrect getting inserted
So, it seems like it would be good to improve this a little
if you look here, I'll quickly switch to the header
I wrote UClass
So, we do this instead
Change the factory
We have a function called TSubclassOF
This is also a kind of class
So it's formed as a template
Here we write ABulletActor like this
Now, we need to make a forward declaration this as well
Writing like this gives an advantage
Where containing BulletFactory in the variables
Will be limited to ones less than
Ones that inherit ABulletActor
In a way it is restricting data types
So if you don't put in right, errors occur
And moreover, the classes that go in here
Are only classes inheriting from ABulletActor UClass can be entered here
Otherwise, you will get an error
It's the compile error
So it let us use strict data types
As they enforce a more rigorous structure
So let's do this and see what changes
Do this and save again
After compiling
Now, back in the player, when you open this
You'll see that it displays
BulletActor itself
Or any blueprint class derived from it
Only these two options are displayed
Here, we'll be using the blueprint class
let's do this, compile, and then run it
Now we can see that pressing the button fires the bullet
Handling the bullet firing sound
Let's add the sound here
We've tried playing sounds before in our last session
Let's try this out with the Star Wars blaster sound
Alright, let's create a folder here
And make a Sound folder
Like so
In the sound folder
Later on, it would be good to add an explosion sound as well
So let's include that together
Let's add these and save
And now, back in the player class
We need to play the sound here
Playing the sound when MakeBullet is called would work well
We could just write the code here
But to recall our memory
Remember when we make sound
We used a node named Play Sound 2d?
Here, we also added the sound Bullet like this before
And you can see it labeled as SoundBase here
So, we should use the same data type as this one
When wondering how to use the function for playing sounds
There's no need to worry
Most of you have done blueprint first
Of course, once you're familiar with it
You can work directly in C++ without needing to use blueprints
If you worked with a blueprint first
It would be easier
Let me show you
If you double click on it
Like this, Reading C++ Symbol shows up
Right here if you look at output log here
The node specifies which function it calls
It looks like it's the Play Sound 2D
Function from UGameplayStatics
You can use this function
Copy as it is
Move over here to the MakeBullet function
After Spawning bullets
After this we will proceed
To use it here
This UGameplayStatics
Require a new header to be included
Like this, include it
So, add the header like this
But now there is some kind of an error
It shouldn't be like this
Let's search for this
Like this
If you search here
There's a fold in front of kismet when including
You need this added
Bring it over here
Write it here like this
After you write it like this, there shouldn't be any errors
Now we are good to go
If you add bracket here
Since it's a function, the first variable
Will be WorldContextObject
And secondly, USoundBase goes in
World is simple
All you need is to do a GetWorld
After that, the sound should be included
There should be some kind of sound after that
Then we need to make it a variable
And fill it in the Unreal Engine, in order to use it
Since this is the Fire sound
Let's make it here
Let's write it down first
We will make something called FireSound
So, let's declare the variable
Go to header file
UPROPERTY
EditAnywhere
And earlier, it was SoundBase
Write class and then USoundBase
With the pointer, write FireSound
Now save all
And then compile it once again
This live coding isn't very stable
Think of it as being in a preliminary service state
So, when your work is fine but keep having errors
Don't get confused and just turn it off and on again
When you restart like this
You should run it from within Visual Studio
Here, you see there's a button
Start without debugging or after debugging
There are two options, but typically you should use this one
If you press it like this, it will start
The shortcut key is Ctrl F5
If you look, it's right here under Debug
Ctrl F5
You can see it starting again
After this
And to the player
I'll also connect that audio file too
If you look here, the Fire Sound is missing
Open it up
Add it back in
Compile it and run to see the sound working well
If you run it
You can see the sound working well
It's a bit loud
If you don't like how loud it is
Like we did before
You can reduce the sound volume independently
Like so
We can just set it like this but
When we fire
Clicking it for each shot is too much work
So, let's try improving this
Back to the player
This time, additionally
When the left mouse button is held down
Bullets fire
When released
Stop shooting
Does it make sense?
Anyway, holding it fires the bullet and otherwise stop firing
But holding it down might fire bullets unrealistically
So, I'd like to create intervals where each shot is fired every 0.2 seconds
We want the intervals
When firing
I want it to shoot every 0.2 second
Like so
To improve this
If you look, there's only a fire action when you press the button
So, I'll improve this function
I'll also try renaming it
It's better to change the name all at once
Here, if you look at quick task refactoring
Not this one
Here's some thing you can use to change names
This one I am using this, so I'll turn it off
If you press Ctrl and R twice
You can change name of the function in the entire project
So let's change the name into Pressed
Preview it
And then apply it
Then it says that it has been changed in three places below
Must be declaration, implementation, and then where it connects
So since we changed it
Let's make one more of this
And name it Released
Released, like so
Write it here
Improvement
Make one named Fire Released
I should implement this too, I'll press Alt and Enter
To create the implementation part for you
Then, we also need to connect it
So for now, save it and move to source file
We also have Released function built here
Go up now
Connect it like this
Copy this entire function of Fire
Its name has been changed to Pressed
This second one, copied as it was
We ant to change from Pressed
If you press Ctrl Space Bar here
You can find the auto complete function like this
Intelligent it's called
So, I'm going to try using IE Released here
Buttons are the same
With the same action
Same action in the game but different behavior
So it can be like this
So, Pressed and Released, we can handle it separately
So then, we need to change the function, Released
Top is Pressed bottom is Released
Change in that order
Like so
We've done it
We've made two of them
Anyway, now we shouldn't create MakeBullet directly when performing an action
We shouldn't do this here anymore
What we need to do here is
What happens now is
I want to activate the shooting functionality for the gun
Should be a concept like this
Deactivate this one
So shoot the gun is now
Will not be activated right when I pressed
After pressing it
We can let it make one some time after
And then make it stop producing when released
So we want to approach it with the concept of activation and deactivation
And the act of making the bullet itself is
The MakeBullet action
Needs to go through Tick operation
Let's change something here
This here is the movement part
And MakeBullet must be done there
To implement this
We will need more attributes
As time passes
And reaches certain time
I want it to make another bullet
Should be processed in Tick
And this one here itself
When shooting functionality is activated
Is the requirement
I'll list the attributes needed to implement this
Firstly, we need the concept of a switch that toggles whether the function is turned on or off
Let's create one as a boolean type
And then bAutoFire
If it's True, take the action and For false, doesn't take any actions
And then the time must flow
Then we need current time
The current time will keep increasing
If the desired time has arrived, that's the concept
In a way, it's similar to clapping
Like so
We use float type for time
Therefore, make a varible
called CurrentTime
And them, another variable called float FireTime
I will set the FireTime as 0.2 seconds
Let me set this 0 at first
This will be initialized to 0 in the constructor anyway
You don't have to worry about it
AutoFire is also a bool type
Let's also initialize this one to 0
And in bool, 0 is false
Typically, bool type
It's yes or no, true or false
For true, if it's not 0 then it's true
If it's 0, it's false
So it's typically initialized to false
Like so
Then I'll try implementing this using that information
I'll copy this part
And try implementing it in the Tick function
Let's start writing down here
Then we have these three concepts like this
So, if the concept of shooting is activated
It would be like this when it's if, true
When you write things like this, you often use phrases like these
I used to write like this a lot in the past too
But it causes us to make mistakes
Because" I can accidentally omit suffixes
There won't be any error
You never know you've made a mistake
It might take one to two hours to find it
Therefore, the trend isn't writing like this
Writing in the left side is a trend
So if you take it out, an error occurs
This isn't something important but
These days, there are trends in development
They say it's done a lot like this
I do it this way as well these days
But my old habits come out sometimes
I sometimes write in the right side
Keep it in mind
So that means we do it like this
So if the shooting function has been activated
I'll say this
First, we'll need to have the time flow
And Second
If current time
Is the time to fire
When the firing time comes
Let's say this
Then I want to create a third bullet
Fourth
I want to reset the current time to 0
If is missing
Resetting to zero is like starting over
Almost like clapping
We have right and left hand
Let's say left side hand is fixed
As right hand moves and meets left hand make a sound
Bring right hand to its original position
Then you can make a sound again
Similar to that, by resetting to zero like this
I'll make it go round and round again by increasing it like this
So then, each time that time comes, it goes tap and tap
Then, at that moment, it starts shooting bullets
Then the time must flow
You can accumulate
And add a specific time to CurrentTime like this
The only time we've learned here up until now is
Just one
Which is delta seconds, delta time
I'll just accumulate this delta time right here
Delta time is the time it takes to draw one frame
For example, if we have 60 frames per second
If we have 60 FPS currently
Then the delta time would be 1/60
If Tick is called 60 times
Then CurrentTime would contain 1 second
Of course 1 goes in
We added 1/60 sixty times, so it becomes 1
So, in practice, when we accumulate delta time until it reaches 1
That's when one second has passed
So, that's how you should understand this
If
CurrentTime has
Exceeded Fire Time
IF the time reached certain time
It means that they have arrived
Time has come" means we've reached that point
I will write exceeds
Then, we want a gun
But it's already implemented
We've already made a function called MakeBullet
Let's create MakeBullet here
This is why I made an extra function
Then we need to reset CurrentTime to 0 at this point
Sometimes people write it here like this
Don't do that
You won't be able to do this forever
Because after adding 1/60
It is reset to 0
So when come back was 0
Another 1/60 cumulates
It keeps becoming 0
That's why this shouldn't be here
But inside here
That way when it reaches, it will reset to 0
We call it interval
We can make intervals
Now let's run it
Compile it
But now that I think about it
For this AutoFire
We haven't implemented the part where it is true or false
Come back down
Right here
We need to enable or disable the shooting feature
So here, we set bAutoFire to true
Here, we'll set bAutoFire to false
And during this process, the time keeps increasing
It keeps increasing
For example, there might be a case like this
Let's say this is true
And Fire time is 0.2 seconds
With current time being 0.19 seconds
In that state, I release the button
When you press again, it will start from 0.9 seconds again
Sorry not 0.9, since it's 0.2 seconds
0.19 seconds I meant
If it starts at 0.19 seconds, the bullet will immediately fire
When you press and release
It might change the sensitivity in such cases
So, resetting CurrentTime to 0 here
Would help start the interval more accurately and consistently
Which should allow for more precise timing intervals
Let's try it out first with these changes and see the results
if you set it up this way, shoots when pressed and stop when released
Shoots when pressed
But we have a problem here
Look, If I quickly
Press the button and release it
Nothing fires
Because I released my hand during the interval, that's why
So this is a kind of problem
To improve this
I want to make it shoot right when pressed
That way, it will shoot as soon as I press it
So when pressed
MakeBullet at first
Create a MakeBullet
So with this setup, we activate the shooting function
Create and fire one shot initially
When goes into interval
Then it shoots normally
So when I click faster, it shoots faster
Something like that
So, compile it again
If we click faster, it shoots well
Let me summarize the content we learned in this session
Bullet Actors, Movement, Input Handling, and Firing Bullet Creation Creating a New Actor Class and Assigning it as a Bullet
UBoxComponent BoxComp declared a collision component UStaticMeshComponent MeshComp declared a visual appearance component
Added the Components BoxComponent header file Added CreateDefaultSubobject
Firing Bullet Functionality Added Tick function for forward movement
Added a float variable named Speed and set it to 1000 Applied GetActorForwardVector for firing in the forward direction
Bullet Creation Function Added Action Mapping in Project Settings under Input Named the new action Fire and assigned it to the left mouse button
Implemented the OnActionFire function Added a MakeBullet function that creates a bullet when Fire is pressed Added BulletActor header file
After moving to the Player, placed BP BulletActor in Bullet Factory under Class Defaults
Automatic Bullet Firing Functionality Improved OnActionFire function to OnActionFirePressed and OnActionFireReleased functions
Created a separate function for IE Released behavior for the same action Added properties for implementing MakeBullet
Handling Bullet Firing Sound Bullet Firing Sound Functionality Created a folder for inserting audio files
Dragged and added the bullet firing sound effect file to the folder Moved to the player and added sound effects when invoking MakeBullet Added PlaySound2D to the MakeBullet function
Added GetWorld and FireSound as arguments to the PlaySound2D function call Added Kismet GameplayStatics header file
The End