Hello, my name is Lee Young hoon
The process of making a TPS game
Typically progresses in the order of prototype, alpha, and beta stages
In C based TPS game development
Understanding design techniques
Using finite state machines is essential for controlling AI
While exploring systems like the skeletal mesh animation system
And navigation system
Which are key components of the Unreal Engine
Therefore, in this chapter/section
In this chapter, we will learn how to create a C based project
Generate a TPS player, and apply a third-person camera and appearance
Furthermore, we will also gain understanding of the character class
And learn about rotation and movement
Using the Character Movement Component
First, let's create a TPS project
And apply the player's appearance
Creating a C based project and generate a TPS player
Let's look at a C based TPS example
First, let me explain what TPS is
There is FPS and TPS
FPS stands for First Person Shooter.
And TPS stands for Third Person Shooter.
So, FPS games are in first person perspective
This one is in third person perspective
Usually, if the screen shows like this
(If the character's hands are only shown, it's first person perspective) With just hands appearing here then this would be called FPS
Next, you can slightly see the full body
If you can see the character's back, then this would be considered third person perspective
This one is third person
So, this example
Let's go ahead and try a Third Person Shooter example like this
Then, first, we need to create the project
Open the Unreal Project Browser
Next, select the Blank template for the game
And here, let's proceed with C for the project
Since the name is Cpp, let's use Cpp as a prefix
Let's name it TPS then
Once the project is created, we can start
By doing the first tasks we need to do
First, I'll change the layout to the form I prefer
And then, I'll create a new level first
Click New Level from this File category
Since this is a TPS, we'll need a ground or floor
So, let's start with Basic this time and click create
And now we need to create the game mode and the protagonist here
Let's proceed with creating these in C
First, let's create the game mode
Click like this
Since this is a TPS, let's prefix it with TPS for the game mode name
Click on Public and then click Create
Then you should see it created like this
Here, if you load it
You can confirm that the files have been created successfully
And now, let's create the main character as well
Find Add C Class from tools
Now, we'll create the character.
You can choose from Actor, Pawn and Character
Actor inherits from Pawn
And Pawn is inherited by Character
Choose character and press Next
This one is the protagonist, so I'll put Player
This is too lengthy, let's just say player
Turns out you cannot use the name player
I will name it TPS player and then press create
Now that we have a new character
I'll proceed to create a blueprint that inherits from this structure
Like so, create a group for blue print class
Then we need a folder, I will make one up here
Right now, it's not working
Hold on, let's create the folder before proceeding
Go to contents and click New Folder
I will name it, Blueprint
And also, we have to save the current level
I will also create Maps folder
Save everything
Come back again, create the main character with prefix BP, under bar
And then create a game mode also
We have been through this process once
We will keep going
Make the game mode as blue print as well
And then save the current level as well
Press Ctrl and S, save it in maps folder and name it game map
We've created everything so, save everything
And then we have to select these in Project Settings
Go to Maps and Modes find Default Maps
Add in the game map for everything
Also, I will not change anything for Default Modes
Let's distribute on World setting of the level
You can also drag it and drop
Here, switch the default Pawn with this one
If you revise it here, also needs to save again
Compile this and save again
We will be keep using this
Go to Save on compile set it to Always
Do another saving entire file
Now then, our main character will spawn here
In this level, we initially have the Player Start
I think the character will spawn here
Now, we double click and change the appearance
However, since we created it as Blank in the first place
We have nothing that's why we go here
I brought data from basic template for the appearance
Go click the add button and go to the upper part
There is Add Feature if you click this
You can bring in existing content if needed
Here, since we're going to use Third Person perspective
Select and click Add to Project
I will bring blueprint and we can use it
To set C , everything comes together
I will use this to import
Now we can see that it's been copied
Now you can close this window
Now this BP Third Person
It's been automatically added
We will not use this
Since we will use what we made
Let's go back to Blueprint Folder
Here, double click on BP_TPS Player
We will set it here
Here, if you inherit the Character
Here, if you inherit from Character
By default, this character has these four components attached
So, this capsule shape serves as the collision component
And there's an Arrow component
That indicates the front direction
Followed by the Skeletal Mesh Component
So, here you would place a mesh
That has a skeleton, and finally
The component is called Character Movement
It's a component used to control the movement of the character during gameplay
So, if you look at it, we see walking, falling and jumping
These functionalities are already implemented
So, let's use these components
We will first, jumping, actions like such
First, let's set up the appearance
Select the Mesh, and then
If you go to Detail, There is a category called mesh
Here, the Skeletal Mesh Asset is currently set to None
If you expand this, you'll see a human-shaped mesh here
Here, what we will use
Is Quinn
Let's use SKM Quinn
Then by inserting this, you establish the pivot point of this character
The origin or pivot point of this character would be at the center bottom
Just like so
We need to lower this a bit and rotate it as well
Since it's currently facing right, therefore
In the Mesh section, at the top, there's a Transform option where
Z-axis down to -90 degrees. The reason for 90 degrees
Typically, models like this are
Standardized with a height of 180 cm
So, if you move it down by 90 cm from the center
It will fit perfectly here
And then we'll rotate it like this along the Z axis
Since clockwise direction increases
Since we'll rotate it in the opposite direction
We'll rotate it counterclockwise by 90 degrees
Here, you can rotate it by -90 degrees like this
This way, you can set it up to face forward
So, if you set it up like this, the camera will
Actually go behind the protagonist character
In 2D shooting games, we typically place the camera
Like this in the level for use
In the case of TPS, the camera needs to follow the protagonist
So, we place the camera here
Click on the Add button here, and let's name it Camera
Now we have the camera here
Place the camera like this for positioning
First, set it up in Blueprint, then you can work on it in C
Placing the camera at eye level like this
Would make it a first-person perspective
Let's save it here and try running it once
Then this happens
If you press F8, it changes the camera perspective to view the surroundings
You can see the player standing like this
And since the camera is positioned at eye level
Pressing F8 again will return to the previous view
That's how it's set up
Setting up the third-person camera and applying the character model
Next, let's configure the third person camera
But you can just add the camera by itself
However, there might be an issue if you only add the camera because currently
It's set up for FPS, so I'll move it back like this
If you set it up like this, you should be able to see the back of the character
So, in this setup, you wouldn't see the front view properly
In TPS games, some have the camera positioned directly behind the character
While others adopt a slightly angled side view perspective
Handling those variations can be
A bit challenging with just one camera setup
So, I'm going to add something
Called a Spring Arm as the parent of this camera
So, I'll use that to adjust the position
And one interesting feature of the Spring Arm is that
Sure, would you like to see an illustration?
In this case, there's a player positioned like this
And the camera is looking like this.
So, there could be a wall positioned like this in between
Then if you look like this, you'd see the wall
Which could be problematic in situations like this
When we add a Spring Arm, which is a component
Designed to envelop the camera
Using the Spring Arm, the camera's position can automatically adjust to move away from the wall and stay positioned correctly on this side
It adjusts to face in this direction
So, that's why we use such features
Let's go ahead and attach the component here and see how it works
Select the Capsule component, click on the Add button
And then I'll name it Spring here
Then the Spring Arm option will appear like this; click on it
Next, I'll place the camera here like this
We'll maintain this hierarchy structure, and with this setup
the camera will be pushed back
Let's reset the camera back to its original position first
And as you can see, the Spring Arm is set up like this
So, I'll raise it up a bit like this
I'm not adjusting the camera directly
I'm moving the Spring Arm instead
I'll push the Spring Arm slightly to the right
Push the Spring Arm to the right When viewed from behind
Let's go around like 40 or 70
If we do this, it should look like this
We can push it a bit further if needed
And if you look at the Spring Arm
Even though we didn't push the camera back separately
The camera is positioned backward
In the properties of the Spring Arm
You'll find something called "Target Arm Length" under the camera section
That's because it's set to 300
If you reduce this to 200 or something like that
You'll see it get closer
And if you set it to 0, it will be right in front
So, I'll set this to 200
And now, let's run it once to see how it looks
Let's proceed to implement this part in C
Let's navigate to the player's header file in this direction
Then we'll find the content we just added there
Here, we've added the Spring Arm and Camera components
And we've specified the Mesh asset for this mesh
I'll write the code for this task
First, let's go to the header file and add the Camera and Spring Arm components
And then I attached the camera to the Spring Arm
Then let's create this first
Write the code for a camera and a spring arm UPROPERTY(EditAnywhere)
Write class USpringArmComponent
I will write springArm for this
And copy the whole thing
Writing the camera cod We need to make a camera too, UCameraComponent
I will call this Cam
I will add this since it's a component
CamComp, SpringArmComp like so
I will create this now
Come to the creator, let's first create the spring arm component
CreateDefaultSubobject
Like so
Put USpringArmComponent for this
I will name it TEXT, always make sure to name your code
Let's just use the same name
This should be attached to the root, right?
For this one, I will use attach
I will add it to SetupAttachment(RootComponent)
And we need to add a header to this, like this
Let's proceed to add the header like this
This has GameFramework
We will need to create a camera as well, right?
Write CamComp = CreateDefaultSubobject
And then UCameraComponent and TEXT here too
I will name this CamComp
I will attach this one to the springArm
Now write SetupAttachment
I will attach this to SpringArmComp
Include the header to this as well
This seems like it should be a Camera/CameraComponent as well
Just like so, finish coding
The third step is to incorporate the input for the Mesh into the actual code
We will use the assets we've put in here
There are two buttons you can see
This means I will put in what I have chosen
This means going to the folder of this asset
If you click on this folder, it will navigate like this
You can see that we are currently using the Skeletal Mesh you are viewing
Right click here and select Copy Reference
Next, when you paste this content into Notepad
It appears as a string like this
You can use this string to perform loading
This is actually the path to the asset
The actual relative path to the asset
So, let's use this to fill
In the values for the Mesh
There is a class called ConstructorHelpers
Here, you'll find template structs named FClassFinder and FObjectFinder
So, with these
The classes are used to load Blueprint classes
Since we're going to load assets, we'll use ObjectFinder
After writing it like this, we'll add angle brackets here
Because it's a template
We use angle brackets to specify the data type
You're not sure yet about the exact data type you'll use right?
For now, let's write it like this
Then, shall we call it TempMesh for now?
Since we're loading a Mesh, let's proceed like this
And enclose it in parentheses to create it
Here, where the string goes, you use TEXT
This one here is data type, then the variable name
This part becomes where you pass arguments
When you call the constructor function
So, here we paste what we mentioned earlier
Into this spot
You need to be careful because
Sometimes when you paste it directly
There might be spacing issues
You shouldn't do it like this
Don't insert it like that, it should be directly attached without any spaces in between
You should use the copied string exactly as it was copied
If you look here, you can see what data type needs to be inserted
SkeletalMesh is written
So, you write that down, and this starts with U
Now, that will work
you'll need to include it to use this
SkeletalMesh comes after Engine
TempMesh is actually attempting to load internally
It will try to read the file, and if successful
Then you can receive feedback regarding that
Use if and then TempMesh was successful
there is a function named Succeeded, by using this function
You can handle it after checking the feedback
Actually, upon inspecting this function
If the object TempMesh exists
It returns true indicating success
If it's null, it returns false
Just like so
So, since we haven't actually created the Mesh yet
We need to handle that part where we assign it to the Mesh
However, when inheriting from Character
Mesh is typically present by default
So, we can just retrieve it from there
You can use the function GetMesh to retrieve it
We can retrieve the Mesh that exists within the Character
Then, after retrieving the Mesh
We can simply call SetSkeletalMesh here
Here, it instructs to insert a new Mesh
This is precisely the Object that was in TempMesh earlier
Right now, after loading
This variable Object contains
An object of type USkeletalMesh
This way, we can proceed with loading
And once we complete this, it means the loading has been done
Now we need to include the Transform information as well
So, let's go ahead and set these values
Here, you can see that
There is a SetRelativeLocationAndRotation function in GetMesh
Using this, you can pass in a FVector
Next, you can pass in a FRotator like this
So, here, it was set as 0, 0, -90 earlier
Let me copy this first
Write these as such here
Then, I'll also copy the Rotator below
If we do it like this, it looks like this
But now we have one more thing to learn here
If you look closely, isn't the Rotator X, Y, Z?
In terms of Pitch, Yaw, and Roll?
Have you learned about concepts
Like DirectX or drones in your studies?
In that context, especially in aviation related topics
You often encounter terms like Pitch, Yaw, and Roll
Pitch, Yaw, and Roll are related to axes information
So let's go ahead and add them here
Since this is 0, 0, -90, let's just fill it in as is
Next, let's put it into Rotator. When you look at Rotator
Here as well, it's set up to input in the order of Pitch, Yaw, Roll, Like this
So, since we need to input Pitch, Yaw, and Roll
If you notice, even though we set Z to -90
Yaw is in the middle position
Warning You should input it as 0, -90, 0 like this
So, paying attention to this point
When it comes to Pitch, Yaw, and Roll
They follow the order of axes
If we visualize axes as x, y, z,
Then it should be y, z, x in terms of order
Remember this for correct usage
When inserting values into a Rotator, it's important to note that the order is not x, y, z
It's the order of y, z, x
Remember the order Pitch, Yaw, Roll
Pitch represents nodding up and down, Yaw represents swiveling side to side, and Roll represents tilting from side to side
When rotating
Then, after setting these, since everything is arranged
Let's briefly shut down the Unreal Engine
and then compile again from here
Also, now that I think about it, for something like the spring arm
We need to specify some more settings
How did we set it up earlier?
Here, for the spring arm, we mentioned TargetArmLength as 200
We set it to 200 like this
We set it to 200 like this, and then we also changed the position of the Spring Length
For this, you would use SetRelativeLocation
Was this set to 0 earlier? Did we set it as 40, 70?
We wrote it like this earlier
FVector is missing
We specified it like this earlier
Let's finish this together. Compile it
And proceed
Then let's take a quick look at the protagonist here
If you open the TPS player and look at the viewport, it should look like this
So, apart from what we've created
The one we previously added in the blueprint is still there
Let's delete that
Let's delete the spring arm and camera components
Keep only the components created in C
You'll see that everything we wrote
Has been correctly reflected
After compiling and running it again, it should look like this
Then let's proceed to handle the input
There's something called Enhanced Input
If you look at the Input here, it's set up like this
There's already existing input handling for this
But since we've done it before
This time, let's try handling it using Enhanced Input
In Unreal Engine, if you look at the Third Person example
There's something called Enhanced Input like this
The basic structure involves creating input actions
And then mapping and handling them accordingly
So, we will create a structure like this ourselves
First, let's create a folder. I'll name it Input
And we need to register two actions as well
In Input, you'll find these actions listed under Input Actions
Since these are Input Actions, we'll use the prefix IA
Let's create one called "IA TPSMove
Duplicate it by pressing Ctrl and D to create another one
Let's create this as IA_Jump I'll save it for now
For Jump, it's set to digital, and it's labeled as a bool
It can handle true/false processing
And when you look at Move, it's set like this
I will open this and select Axis 2D
Because Move involves using two axes
So I will specify it as 2D
And right click with the mouse
Then in Input, this time we're going to create a Mapping Context
Create it like this, and since this is for the IMC for player
Set the name as TPS Player
And double-click
So, it's set up like this for mapping
You can add them one by one by clicking the plus sign here
Let's open this up and put in the two things we made
We will put Jump and Move in there
To activate the button corresponding to Jump
We need to handle it by pressing the spacebar
For movement, there should be four directions: W, A, S, D
I'll assign forward and backward movement to X
Because the front and back are along the X-axis, and left and right are along the Y-axis
I will assign forward and backward to the X axis and left and right to the Y axis
Normally, the order is x, y, z
As you can see here in the value type
It's labeled as Axis 2D and set to Vector.
Of course, Vector follows the order of x, y
So, I'll set it up like this
First, let's assign the keys
I'll use W and S for this, interpreting it as the Vertical concept
I'll use A and D for this, interpreting it as the Horizontal concept
Pressing W will simply result in 1
Indicating it's pressed, and when it's not pressed, it'll be 0
Then S should be -1 when pressed
So, I'll add another one in the Modifier section here
There's a 'Negate' option, which will make it negative
So, for the W above, a value of 1 will go into x
And when pressed, it will be 0 if it isn't pressed
And S will go into x with a value of -1 conceptually
So, I've set up these two basics
Now, I'll need to set up A and D
I want to assign A and D to y
So, I'll add another modifier here
here's an option called Swizzle
If you expand it, there's an Order option
Where you can reorder it to y, x, z
Remember, it's about putting values into the leftmost axis
So, it will go into y when swizzled
Swizzling allows you to customize the values as you desire
First, we're using Swizzle to put them into y
Then, A will be negative and D will be positive
We'll need to apply Swizzle to D as well
This way, both A and D will be assigned to y
But D is positive, so we can leave it as it is
However, for A, since it's negative, we need to put in -1
So, I'll add one more and apply
Apply negate here
If you set it up like this, it should work
When you look at the whole setup W remains unchanged, S is negated
And A and D are handled accordingly
Also, we'll need to handle mouse rotation
Let's add one more input
Copy Move input
And name it Look
Then, I'll add a mapping here
Set this one as Look
Look will take mouse x and y inputs
So, mouse x and mouse y
Just like so
Since it's x and y, we should Swizzle y to receive it
And you'll see x is left and right, but y is up and down
Usually, the mouse and actual coordinates are opposite
So we'll include Negate here as well
That's how I'll set it up
We'll move to the TPS class
Then to TPS Player and scroll down
Here, we'll include IMC and IA inputs
UPROPERTY(EditAnywhere) This way, you will be able to contain it
Write class
UInputMappingContext and name it IMC player
Just like so
And we also need to register actions
Like this, it's UInputAction
Here, instead of IMC, we'll name it IA_Move
We'll copy it as is and add another one for Jump
Besides Jump, we'll also add Look under Move like this
Then, we'll need to create functions corresponding to these
Let's add void OnIAMove here
Next, we'll connect three functions
Move, Look, and Jump
Each of these functions will have parameters
write const and there is something called FInputActionValue
Ampersand then write value
In order to use this, you'll need to include the header like this
Should we quickly search this?
If you search it like this
It's set up like this; just add this, and you'll see that
The module is named EnhancedInput
So, if you come over here, I've already written it down
It should be written like this for you all, too
Here, add a comma and then enclose it in double quotation marks as a string
EnhancedInput that was mentioned here earlier
Let's write EnhancedInput right here
You need to register the module to use the class
Once you register it like this, include it
When you use it like this at the top
When you do this, make sure to write it above
Generated at the top
I'll proceed to add them all in the same manner
Let's create the implementation
Shall we compile it first?
There's an error compiling
Unreal Engine is open, so there might be a compile error
Let's close Unreal engine
Try compiling again
Then you should see it compile successfully
Sometimes you might see red lines like this
You can ignore these for now and continue
And now, we register and use this
Let's move to TPS's BeginPlay and write it there
First, let's bring the player controller
Let's call it auto pc and cast it
Currently, we're controlling this player
We can get the player controller
Cast it to the player controller.
Write APlayerController like this
Once casting is successful, verify that we're controlling the actual player character
So, write GetController
After retrieving it, if the casting was successful and pc is not null
if it's not nullptr, you can proceed to write it like this
You also can write just like this
Then there's ULocalPlayer take a look here
You can retrieve ULocalPlayer with Getsubsystem like this
This is in a template form
Write UEnhancedInputLocalPlayerSubsystem here
Just like so
You can fetch the Local Player
From the player controller and assign it
Obviously, we need to add the header for this
Let's search for this as well
Let's try using the include that's here
You can just add it like so
We should receive this first
This one returns the subsystem
Let's retrieve it with auto subsystem
After doing this, we should also perform a null check on it
If it's not null, then for the subsystem
Wait, let's compile it once and then proceed
Compiling was successful, and now, clear from the subsystem
Autocomplete isn't working, but I'll type it out
we'll clear out all the existing mappings for now
We will redo the mapping
We call the function AddMappingContext
And add IMC Player and 0
This is similar to a priority concept
We'll use this directly
I'll add it like this and register it
Implementing this and registering it here would make things easier
Let's register it
To register, we need to cast
If you see, there's UEnhancedInputComponent
It is UInputComponent
We will use it by casting
We'll cast it like this and use it
There's also CastChecked
CastChecked conceptually includes null checking as well
I'll cast it like this and proceed to use it
Just like so
To use this, you'll also need to include the header
Automatically add the header
You'll see it reflects well when you do it this way
I'll try adding this in a similar manner
Errors keep occurring
I'll add this one as well
I have included these two like this
Resolved error with includes If I build it then the error goes away
Then we need to establish the connection here
Let's proceed with binding
In case of EnhancedInput
EnhancedInput has both Actions and Axes
All inputs are configured using BindAction
Write BindAction
Next, if we were to start with Move
We should add IA Move
And then in ETriggerEvent, it looks like so
There's Triggered, and then Started, Ongoing, and Completed
More various codes exist
Typically, for handling Axis, you would use Triggered
Then they can keep coming
Then, for button handling
You can use Started and Completed
So, since this is for Move, Triggered should do the trick
Write in this, then you put the function's address here
It's not significantly different from the usual method
Register it like this
And similarly, I'll copy and paste this
To handle Lookup as well
This one will be Look
Let's also handle Jump too, since it's button based
Like this, we'll handle Jump
And for this one
Since it triggers only when pressed, we'll use Started
Have this as Jump
Handling player movement and rotation
Next, let's implement handling
Player movement and rotation
Let's move somewhere else
To do that, we need to save the direction first
Since we can't directly use the values passed here
Let's create a variable named Direction
And store them in a Vector
We'll store it and We can't use it right away
So let's fetch it from value
We can bring value using get
For Move, as I turned off
Move is implemented as FVector2D
Bring it just like so
In order to do that, do as I do
Then simply assign the values from here to this variable
Assign x to itself in the x variable
Since we're using x and y
Then we'll assign y to the y variable like this
(Lookup rotation functions AddControllerPitchInput, AddControllerYawInput) And for Lookup, rotation uses these functions
What this does is
It takes input rotation values and stores them here
Maintaining rotation information
Next, where will this be applied in the character's code
Needs to be decided
For now, we'll handle Pitch and Yaw here
Because Pitch and Yaw are
Pitch is nodding up and down while Yaw is swiveling side to side
So, we'll rotate like this, swivel like this, and turn like this
So, we'll use AddControllerPitchInput and AddControllerYawInput
Let's use both of them
That should work and now, we'll need to fetch from here again
In a similar manner, we'll fetch it like this
Because on the mouse, x is left right and y is up down
Nodding would correspond to y
Let's assign vec's y value here
When you assign vec's x value like this
Characters can nod and swivel movements like this
Next, for Jump, we do it like this
Just label it as Jump
By calling the Jump function like this, you can perform a jump
That's how you implement it
Then, you'll need to implement
The actual movement in the T part
In the case of a character, there's a component called Character Movement
You'll use that to handle the movement
There's a function called AddMovementInput there
You just need to pass Direction here like this
But here, you're continuously filling in the values for Direction
Then it will remain here like this
So it will move even without me pressing any buttons
So after handling Direction once
Make sure to always initialize it with ZeroVector
So the value is only set when pressed, and becomes Zero when released
Then it won't move, like so
Let's take a look at the results
It's necessary to implement all the input handling for the player
Here is where the input will go
Let's put our custom IMC here
Next, for Move, select TPS related settings
For TPSLook and TPSJump, you can assign them accordingly
Compile it and let's run it to check
I can rotate
Rotating works fine and I can also move my character
I've made some settings for the rotation
You'll find the basic rotation with these three selfs
And then there's the spring arm here
Also, there's the character movement
Take a look at rotation,
And if you search for it, you'll see it's checked here
It says Use Controller Rotation Yaw in Pawn
But originally, it wasn't checked here
So, when you run it
Rotation will likely only happen this way
While movement will work fine
The movement feels strange too, When I look behind, I end up moving backward
Pressing w results in an unnatural feeling of movement
I can see that it only moves forward like this
These issues must be dealt with
let's start with rotation, rotation typically looks like this
If you input rotation values into AddControllerPitchInput/YawInput
You're effectively holding
Rotational information in those inputs
Reflecting this involves
Applying rotation through the options here
So self essentially refers to the TPSPlayer itself
I'll use the controller's values
For the rotation axis of TPSPlayer's Yaw
So if we check Pitch, it would look like this
Where rotating causes it to lie down like this
Pressing F8 like this allows you to escape
This is what happens
So, what we want is not this
We want Pitch to rotate the camera only
Not affect the character's orientation
So, we'll leave this as it is
Select Spring Arm and check Use Pawn Control Rotation
When we run it, it will handle things like this
Next, for jumping, you do it like this
But finally, it seems like
You need to move in the direction you're facing
Right now, you're moving in an absolute direction
Even if you're facing this way, you're moving forward like this
Let me try to solve this for you
Coming back to the player
we move on to Tick and In Tick, we'll handle this
This Direction is currently an absolute direction
What we want is for this absolute direction to rotate relative to me
So, what I mean is that currently, forward is absolute
What we actually want is for these directions
like east, west, north, south
(Making it move relative to me) I want it to rotate relative to me
We'll adjust the Direction value to reflect this relative positioning based on me
Here's how you can do it
Write Direction FTransform
Then find GetControlRotation
It takes the rotation values received from the controller input directly
Right now, we're inserting it like this
Then we fetch the rotation values stored there
Then, using that as a basis, there's something called TransformVector
In Blueprints, this is labeled as TransformDirection
But in here, it's named TransformVector
You just need to input Direction here and then perform the transformation
This will return the orientation with the axis swapped
Based on the current state stored in the controls
Then I'll compile this and see the results afterwards
When I run it and if I look this way and press W
I start moving in this direction
That's how it works, enabling this kind of control
As for the player, the way we've set it up now
We can't see the face
If I try rotating like this
You never get to see the face
You can only see the back of the head
Typically, in role-playing games, RPGs
You can see the face in such games
Even if you can see the face when you press w
The character turns its back and moves forward
We can also handle this as well
Turn off these controller rotate
Then, go to character movement
And search Rotation
Then, you will find Orient Rotation to Movement
Check that and try it on after compiling
Now I can rotate freely, able to see the face
And if I press w here
The body rotates relatively to the direction I am facing
With w button pressed, character would rotate like this
Not pressing w looks like this
If you use this function
Whenever you are creating desired contents
Depending on the concept establish could lead to different settings
But, since we are making TPS, we don't really need to see the face
Will be satisfied just with the back of the head
So, I will check this
And then there is an issue with jump too
As you can see, the character jumps like this
If I wanted to jump twice, I can easily set it up
Go to character, turn this thing off
If you press 'Self' here
And search for Jump Max Count
You'll find this, it says 1
If you change this to 2, you can jump twice
Depending on how you set this value like this
You can change the number of jumps
And if you look here in Character Movement
You can configure settings for jumping here
There are options for Jumping and Falling
Here if you take a look, there is Air Control
There are more stuff to this
Here is Air Control
It's set to 0.05 which means
The force taken while in the air after jumping
It's set to a very small value
So when you jump and try to press in the opposite direction like this
It doesn't seem to offer much resistance
It feels like the character continues moving in the direction it jumped
It feels like keep moving in the direction I jumped, without much resistance to change direction
If you want to change direction in the air as well, you can increase Air Control value
Let's increase to 5
After you compile and run it
When you press in the opposite direction, you should feel more resistance
This way, you can control your movement in the air
You can refer to these settings to proceed with your work
Let me summarize what we learned in this chapter
Creating a C -based project and generating a TPS player Understanding character class
FPS First-Person Shooter TPS Third-Person Shooter
Applying the appearance of a TPS character Game designer, artist, programmer
Applying Third person camera and appearances
The role of SpringArm Automatically handling situations where the camera view is obstructed
When there is a wall between the camera and the player, using a spring arm To automatically move the camera's position beyond the wall
If the camera automatically moves backward, decrease the Target Arm Length
Handling player movement and rotation
Role of CharacterMovementComponent Components used to control movement when manipulating the actual character
Handling movement, Lookup rotate function AddcontrollerPitchInput, AddcontrollerYawInput