Pawn Controller Rotation in Multiplayer
I am currently creating a rolling ball game in which the player controls a physics based pawn in a third person perspective and can roll around using AddForce.
I am attempting to implement multiplayer functionality using a listen server, however i am having difficulty getting the pawns rotation to actually work. Here is how i have the entire thing set up.
For now i have 1 function to control the Vertical movement Movement of the pawn (forward) which takes in a float value (obtained from the inputaxis). From here i am using Controller->getControlRotation() to obtain the current rotation of the controller and then multiplying it by the axis value and of course the roll speed of the ball. (This moves the ball in the direction the camera is facing). This function is running server side. In order to get this to update to the clients, i have a client side function that runs in the tick event and simply sets the ActorsTransform based of what the server has calculated it should be. This works on multiplayer perfectly without any issues.
However, when attempting to set up my MouseX function (the function to rotate the controller via AddControllerYawInput()) in the same manner, it just doesn't work. If i have the function set to run on the server, the player cannot control the rotation (It just doesn't move). If i set it to NetMulticast/Client the client can control the rotation but the Forward Vector isn't effected by the rotation.
How would i go about setting this up correctly?
GIF with explanation Below: https://puu.sh/BhFvQ/ea78a9281a.gif
As you can see from the GIF above, the listen server (Left) can roll around, moving in the direction the camera is facing, it is replicated to the other clients which is perfect. However, when controlling the client (Right), you can see no matter where the camera is facing, it will always roll in the same direction. The movement however, is replicated back to the server which is working perfectly. Its just the rotation aspect that i cannot figure out.
asked Aug 21 '18 at 01:04 AM in C++ Programming
Solved this after 2 days of pure headache!
Solution: I created a FRotator variable that stored the controller rotation. I created a overloaded function to set this and called it everytime the MouseX input was used. This function was set to run on the server using UFUNCTION(Server, Reliable, WithValidation) This provided the server with the rotation from the client and the vertical movement was now working correctly!
Follow this question
Once you sign in you will be able to subscribe for any updates here