Announcement

Collapse
No announcement yet.

Replicate Character Rotation between Client and Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Replicate Character Rotation between Client and Server

    Hey Guys

    I'm struggling a bit with getting the replication to function correctly between my client and server. At first I used the "Pawn" class for my custom class but soon found out that the movement doesn't replicate, so you'll have to create you own replication code. I got it working but not 100% correctly. I then switched to using a "Character" class as the movement component already had replication and network smoothing build in. The problem I have now is that my movement is replicated correctly over the network but not the rotation. The rotation is correct on the client, but it's not being replicated onto the server.

    Does the "Character" class not replicate rotation ? Can anybody help me in getting the rotation to replicate ? Also. Does the "network proxy ( ie. the clone of your pawn on the server) " of your pawn not have a controller ? I'm very new to all of this so still trying to get my head around it.

    Thanks
    A

    #2
    The rotation is correct on the client, but it's not being replicated onto the server.
    Replication works in opposite way - variables from server replicates on client. For sending data to server you need RPC.

    If you're using simpleMoveToLocation or even moveTo then you right - it doesn't replicates correctly. If you move/rotate a pawn by yourself, you can hold location/rotation variables, make them replicatable and on the client you'll have correct values.

    Comment


      #3
      But at the moment I'm not calling the MoveForward or MoveRight functions only on the server. I haven't specified any UPROPERTY() for those. So how do they then replicate but not the rotation ?

      I'm using "AddMovementInput" for the forward/right movement and "AddControllerYawInput" and pitchinput for the rotation.

      Comment


        #4
        Because Character holds movement component and it's replicated by default (you can check it in blueprint). It seems that rotation is managed differently or not managed at all. So you need to add add some field, say MyRotation make is replicatable, on user input you say server to change characters rotation and you'll get correct value on client. All you left to do - update orientation with this value.

        Comment


          #5
          Ok thanks, I'll give that a try when I get home. Maybe one of the Devs can shed some light on why the rotation is also not replicated by default ? Or if we have to do something differently perhaps ?

          Comment


            #6
            Hey guys. Ok for some reason it's working now. I'm updating my pawn's rotation locally and calls a function on the server that updates it's rotation. It's working 100%.

            Comment


              #7
              what is the function you are using on the server to update the rotation? because I'm having the same problem.
              My website: www.jaspercousins.co.uk

              Comment


                #8
                I just got over this hump myself. In my game the character is controller normally through wasd and rotates towards the mouse like in Alien Swarm. The rotation is calculated every tick and I call an rpc every net update interval to set the rotation target on the server, which is then propagated to the other clients through a replicated variable. The non-controlling clients interp towards the desired rotation every tick. In my version, I had issues with floats getting a little jumbled every now and then which would cause them to twitch a little, but only when standing still, so I added in logic to not update when the rotation hasn't changed. Not sure this is 100% the best way to do it, but for now it works. If it shows issues in playtests down the road I'll scheme up something better.

                Comment


                  #9
                  Hello guys. I have a similar problem. I've been searching the forums for a solution but it seems that I can't wrap my head around it. I am new to UE4 (and especially networking), I understand the basic concept of networking on UE4 that the client must always send info to the server and the server will replicate to other clients, but still I can't figure out what is wrong in my handling.
                  Here is how I am doing it:
                  - On the controller blueprint I am handling the player inputs: Every tick I calculate the rotation where the character should look at (this in handled in the CalculateMouseInputRot macro) and set the ControllerInputRot variable. After that I notify the server about the rotation of the character by calling an event which is located on the character blueprint (the macro NotifyServerAxis is triggering this event)
                  Click image for larger version

Name:	4Gaheu6.png
Views:	1
Size:	208.6 KB
ID:	1091702
                  - On the character blueprint I am handling the server event and set the calculated rotation into a local replicated variable PlayerRot, set the rotation of the character and trigger another event which will multicast on all clients.
                  - On this multicast event I just update the rotation for all clients.
                  Click image for larger version

Name:	TmAzLMZ.png
Views:	1
Size:	147.8 KB
ID:	1091703

                  I really can't figure out what am I doing wrong. Can anybody have a look and maybe give me some hints?
                  Thank you!

                  http://i.imgur.com/4Gaheu6.png
                  http://i.imgur.com/TmAzLMZ.png

                  Comment


                    #10
                    This works: https://youtu.be/WFAy5nYWCRE

                    Comment


                      #11
                      Coming across this problem in 2020 and still none of the solutions here are optimal.

                      RPCs should be for one off events and shouldn't be used in tick events to update a variable. Variable replication is done only roughly 10x per second so as not to overload the network rather than each tick.

                      The server should already know about each characters rotation, it just isn't multicasting it.
                      The best way I've found to do this is create a rotation variable in the character/pawn and set it to replicate. Then in the tick event, update it from the control rotation.
                      I just needed the pitch because the yaw already replicates fine.

                      Character Blueprint
                      Click image for larger version  Name:	Capture.PNG Views:	0 Size:	258.5 KB ID:	1752085
                      Last edited by Mipmap Games; 04-28-2020, 05:50 AM.

                      Comment

                      Working...
                      X