In the previous article, I created a custom Character, but only a line of log shows that I used my own Character and can’t do anything. Here, I will record my modification of my Character. The process
The first step is to open the project, hahaha.
The first step is to add a rectangular moving Logitech, which is to define the keys of the keyboard, open the Unreal Engine, and perform the keyboard Button definition.
Open the project settings and enter the project settings interface
< /p>
Find the input
I It will be ready to realize the movement of ASDW, and the movement of the mouse up and down, left and right.
Set according to the figure below and it will be OK
< p>
After designing as shown above, we need to go back to the compiler to press the code. Go up
After a part of the code, compile
A few lines of code realize the movement of the control role of the asdw button
The core code, how I know a lot about the algorithm here, roughly means to get the movement vector from the matrix, and call UE4 system functions to move the character
Now my character can be moved, but it still cannot be rotated. Now I need to add mouse time so that my character can Spin.
It is still similar to the sector operation, edit–>Project Settings–>input
Okay, now the new part
Transfer to the compiler and add the rotation function And look up and down functions
New functions
Binding function
The implementation functions here, we can see in the APawn class,< /p>
Here I am going to take a shortcut, hahaha
Seeing a miracle
It’s all right here
Compile
okkkkk
< p>
So, most people disdain to take shortcuts, do you like your own code, you can learn from the implementation here
< /p>
Just search for the function directly here
Here is the implementation of the actual function, you can copy it directly
void APawn::AddControllerPitchInput(float Val){ if (Val != 0.f && Controller && Controller->IsLocalPlayerController()) {APlayerController* const PC = CastChecked(Controller); PC->AddPitchInput(Val); })void APawn::AddControllerYawInput(float Val){ if (Val != 0.f && Controller && Controller->IsLocalPlayerController()) {APlayerController* const PC = CastChecked (Controller); PC->AddYawInput(Val); })
Now I can control my custom character to move and rotate
< br>
TIP
When using the binding function, it reminds us that we need to pass in the function pointer, that is, we need to add &
in front of the function
< br>
Attach a link here https://answers.unrealengine.com/questions/200444/input-bindaxis-c.html, you can refer to