Announcement

Collapse
No announcement yet.

Getting Player Controller in Multiplayer

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

    Getting Player Controller in Multiplayer

    So I'm working on a 3D side-scrolling platformer, wherin the character shoots at things in the environment. The aiming done by where the mouse is. Here's the blueprint:

    Click image for larger version

Name:	mouseshoot.jpg
Views:	1
Size:	216.2 KB
ID:	1142501

    This works perfectly on the Server, or 1 person. However, If I play with two players, the second player (client) does not aim correctly, or at all. If I choose dedicated server, it also doesn't work.

    I realize this is probably because the player controller is set to 0. However, when I set the player controller to 1, 2 or any other number, this setup does not work at all.

    Why isn't it working for player 2?

    #2
    Hey what class is this in? The pawn? Or a UMG widget? If its the pawn then use get pawn controller, or if a widget, get owning controller.

    Comment


      #3
      Yes, this is in the pawn class. I tried typing in 'get pawn controller' and all I could find was 'Get Controller' which is incompatible with 'Get Viewport Size' and 'Get Mouse Position'

      Thanks for the reply

      Comment


        #4
        Ah thats probably because its returning a controller class and not its subclassed playercontroller.. Or the other way round. Ill mess about in the editor tonight and see if i can figure it out, im sure ive done something similar before

        Comment


          #5
          Silly me, the problem was that the player controller doesn't exist on the server, so the instance of the character pawn that exists on the server would check its controller's mouse position, and it would always be zero. Basically you need to make a remote procedure call (RPC) (a custom event) that is triggered on the client, and sends the info to the server. Its confusing because there are more than one copy (instance) of the same object.

          Click image for larger version

Name:	rpc.jpg
Views:	1
Size:	149.9 KB
ID:	1064784

          This should work, I tried to copy your blueprint as best I could for a quick test, I used a print string to make sure the client was successfully sending off its data every tick, and both the client and the server pawns are registering mouse input.

          So basically every tick (you could trigger the info sending however you want, custom event or calling the function or something), the local instance of the pawn, and only the local instance because of that "is locally controlled" branch check, does all the computing you had before, and just sends off its result via a custom event. The custom event is set to "run on server" with reliable checked. It also has a parameter of type float, that sends the data along, delivering it to the instance on your pawn on the server.

          If that scene component still doesn't move it may be because that component is not set to replicate, this could be solved with another RPC I believe.

          Sorry if its a bit confusing, hope it helps a bit

          Comment


            #6
            Originally posted by zombat View Post
            Yes, this is in the pawn class. I tried typing in 'get pawn controller' and all I could find was 'Get Controller' which is incompatible with 'Get Viewport Size' and 'Get Mouse Position'
            You can cast the Controller returned by Get Controller to PlayerController - then it should work.

            Comment


              #7
              Zuriel!

              Thank you!

              It works! Fantastic!

              mpie - I tried what you recommended, but it didn't seem to work.

              Comment


                #8
                How do I use to logic to make a character move to a click's location on multiplayer?

                Comment

                Working...
                X