Announcement

Collapse
No announcement yet.

How can I replicate character rotation?

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

    How can I replicate character rotation?

    Hello,

    I've been trying to get rotation replicating properly in my prototype. I've tried a variety of methods and while the rotation seems to be replicating well from the server to the client, the client's character seems to be maybe double-transforming for some reason. You can see my problem in the video below where the server is the controlling the character on the left and the client is controlling the character on the right.



    Below is the relevant graph from the blueprint of the character which derives from Character. The SmoothRoll event is called on Tick in the same blueprint, and PawnRotation is set in the player controller blueprint. VertSpeed is set on Tick.

    Click image for larger version

Name:	Screen-Shot-20190324-at-9.05.12-PM.png
Views:	280
Size:	56.1 KB
ID:	1599481

    Click image for larger version

Name:	Screen-Shot-20190324-at-9.03.46-PM.png
Views:	334
Size:	488.7 KB
ID:	1599482

    I've tried many different methods but I must be missing something. If you can suggest the most efficient way I might make the client's character behave like the server's, I would appreciate it.

    Cheers.

    #2
    Guess: Maybe because it is locally controlled?
    [LEGENDS of EPICA][Twitter][FB][YT][Vimeo][Reallusion Technical Expert]

    Comment


      #3
      Hi unit23.

      The character is controlled by its player controller. Whether a character has authority or not, it will eventually execute the same multicast event that executes SetActorRotation as depicted. If you think being locally controlled is the problem, how might one alter the character to not be locally controlled?

      Thanks for your time.

      Comment


        #4
        Any suggestions would be appreciated.

        Thanks for your time.

        Comment


          #5
          Have you tried setting the Pawn Rotation variable only from the server? Without context, it appears it could be an issue where your client is setting it, then the client gets a replicated value from the server, rinse and repeat.

          Along the same line of thinking, you're setting the rotation locally, and then multicasting. The client and server will always have disparity here. In your example, the client sets it to where it is now, the server multicasts, and even with 20ms round trip delay (right in PIE a small amount of delay between the client and server is still present), by the time the client executes the multicast RPC, it will be setting it to the rotation that it WAS, not where it should be right now. Since the client and server will never have instantaneous communication, multicasts will always result in a client seeing things as they were, x milliseconds ago.

          Your paradigm is not flawed, you're doing things how you should be. You're just not accounting for the delay between the client and server.

          The easy approach is to simply not execute the multicast logic on the owning client, since they are already locally rotating. This will make the client see it as it should be, and the server/other clients will see the same but with a slight delay. On your multicast RPC, you could try only executing if the pawn is not locally owned.

          The more difficult approach is to account for the client's lag on the server, and sending the multicast to where the rotation should be in x milliseconds, where x is their one way trip time. This works for some games, and not others. Example, dodging. Client A fires at Client B, Client B dodges. If the server sets the position of Client B based on their lag, Client A sees at least some "teleportation" occur. In scenarios like this, a more refined approach is necessary, such as speeding up an animation by x milliseconds instead of simply setting the position. That, of course, comes with the drawback that higher latency players end up dodging much quicker for other clients, and can lead to "wtf?" moments.

          Without context, it really looks to me like you've just got to account for the disparity between the rotation as it exists on the server and client. For now, testing the easy approach will take the least amount of time, and if it runs smoothly at that point you know this is the issue.

          Comment


            #6
            That sounds like some really good advice. I'll give it a shot implementing it this weekend.

            Thanks so much.

            Comment


              #7
              Any time, I hope it helps in this scenario. It's always hard to tell what the exact cause is. Let me know how it goes

              Comment


                #8
                I return with news.

                After cleaning up the redundant code, my graph now looks like this:

                Click image for larger version

Name:	Screen-Shot-20190331-at-2.18.04-PM.png
Views:	257
Size:	454.2 KB
ID:	1601325
                I don't understand why but it seems that the jittering is gone. It returns if I remove the IsLocallyControlled branch. I also don't understand why a check of local control on the authority should affect the jittering of the remote.

                Replication works with the above setup. Sometimes tidying your code fixes problems one couldn't solve before.

                I have a new problem however. It would seem that my rotation is not frame rate independent and I don't know how to make that so. As you can see, I've clamped the value of VertSpeed in an attempt to stop the character from over-rotating on slower clients but this leaves me with the slower clients rotating more suddenly than I'd like. You can see the current state of the rotation in this video where the server is on the left and client is on the right:



                I think the source of the problem lies in the function I use to set VertSpeed here:

                Click image for larger version

Name:	Screen-Shot-20190331-at-2.32.14-PM.png
Views:	250
Size:	92.4 KB
ID:	1601326
                As you can see, if a computer has a slower frame rate, more time will pass between ticks, and thus a larger number will be read into the Target pin of FInterpTo. Alas, I don't know how to normalize this value. It seems this questioner HERE had the same issue though.

                Thanks again for your time. All advice is appreciated.

                Comment


                  #9
                  You're doing essentially what I said in my response. The multicast is not run on authority only, it's run on all. Like mentioned in my prior post, you were conducting the rotation locally, and then the server was multicasting the exact same thing so the local player would bounce back-and-forth between its own logic and the multicast. Making sure the multicast does not occur on the local player removes the back-and-forth.

                  Interpolation nodes already account for framerate, which is why it accepts the delta time. Why are you accounting for delta seconds in your target? In the screenshot, you're accounting for delta time twice, which will result in exactly what you've stated. Either the target should account for delta time, or the interpolation. Not both.

                  Comment


                    #10
                    Even removing the locality check after the multicast event fires still sees the rotation replicating properly. That's what really confuses me. I thought I needed that second check but it seems not.

                    Click image for larger version

Name:	Screen-Shot-20190402-at-8.42.13-AM.png
Views:	259
Size:	428.2 KB
ID:	1602002

                    I tried removing the nodes I circled in the image in my last post but without those nodes, the character just spins around and around as I hold the direction key. It looks like it might be not taking the shortest route for interpolation and instead resetting to 0° from say, 1° by spinning °359 instead of just -1°. I'll investigate more this evening.

                    Thanks again for the help and patience. Many of these concepts are new to me.

                    Comment

                    Working...
                    X