How do I scroll camera on each player in multiplayer?

0 favourites
  • 12 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I cant seem to get the camera to stay locked on each player in a multiplayer format. The game has players able to run around in 1 "world" map. I have tried every tick scroll to player and behavior scroll to object. I have also messed around with "for each player" and strings like that but when the 2nd player joins the game there camera doesnt stay on them. It just wont work. Any ideas? (The camera just needs to lock on to each player and stay on them with them in the middle but getting the camera to behave individually for each player seems to be the issue).

    Example:

    Player 1 joins and can move around the map no problem and they will always be centered on camera (typical scroll behavior)

    Player 2 joins and the camera will not follow them at all.

    Any help is much appreciated!

  • Did you figure anything out. I have got the exact same issue. Spent days trying to solve it. Still haven't!

  • You need to assign the peerid to each player and then select player where instance = peer and set scrollto... this will set it so that each player scrolls to just there player

    In my example I have global var called MyPlayerID which is the peerid from the multiplayer instance. When I spawn the the player I set its id variable to the peerid as well. then I select the player where id = MyPlayerID and set scroll to for just that object. Ignore the single playertest condition from my example as I use it that when im testing the game in single player mode

    [attachment=0:3qksmq7k][/attachment:3qksmq7k]

    Hope this helps..

  • You need to assign the peerid to each player and then select player where instance = peer and set scrollto... this will set it so that each player scrolls to just there player

    In my example I have global var called MyPlayerID which is the peerid from the multiplayer instance. When I spawn the the player I set its id variable to the peerid as well. then I select the player where id = MyPlayerID and set scroll to for just that object. Ignore the single playertest condition from my example as I use it that when im testing the game in single player mode

    [attachment=0:2jbxqkye][/attachment:2jbxqkye]

    Hope this helps..

    can you upload CAPX for example ?

  • [attachment=0:1yxn2g5u][/attachment:1yxn2g5u]

    Note: You will need the MoveTo Plugin by Rex for this to work

    Ok so here it is... Its a little complicated and i got really lazy towards the end so I revisit later and upload with full comments (maybe make a tutorial) but here you set the room name, and player name and then connect. Each player will only scroll to them selves and see whaty other players are doing at the same time. (Also i got lazy and it only supports 2 players so if more than 2 go in the room it will break)

    Any way I also do things very different from how Ashley does (no discounting his genius i just do things different). I hated the lag that occurred from associating objects so i built a highly compressed data transmission method. What I do is make everything a function call and simulate actions. When player 1 presses left.. he calls a function to simulate moving left on his screen and at the same time sends a multiplayer message to other players as a dictionary JSON string they the decode and tells them to call the exact same function for player 1 on their screen.. Everyone sees the same thing and instead of syncing for every X,Y change i send a single message and tell it to persist until i tell it to stop. the move to is just the last peice that fires off to ensure the players are where they are supposed to be on each other screen.

    Take a look.. Hopefully it helps.. Again I'm sorry for not commenting but i got a little tired pulling this out of my code to make an example.

  • troublesum : why do you do things so complicated ? Sending each time a message and broadcasting is slow, and use a lot of bandwidth !

    The Multiplayer component is made because data are transmitted as binary (low bandwidth use). It's why you can't (for now) sync text variables.

    javissupreme :

    Read this : https://www.scirra.com/tutorials/915/mu ... ame/page-6

    Your "Scroll" behaviour have to be disabled at first.

    Now, at the step of enabling "Input prediction", here, you add the "enable scroll behaviour" action. So each peer will have the scroll behaviour activated only for his player object.

    And you have to do the same idea for the host.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't think you understand.. to move a player half way across the screen I send 3 packets (3) instead of sending hundreds of x,y position for every change and have choppy lag for input prediction.. i assure you this is more compressed and more accurate as there is no lag to account for. did you try it and see how smooth immediate the changes are?

  • I didn't have the download link (edit : now i have) but i understand what you mean. I had the same problem on my games about the players re-spawning.

    It depend on the case you have to solve. Maybe it's interesting to mix both of them.

    Because in the case of moving, i don't think it's a bad solution to let the system working.

    Now for special uses as placing players on the screen, it's faster to use your function.

  • I should make a correction.. the only lag to account for is if the receiving device runs slower than the sending... for long persisted action calls i inject a set position every half second or so on my games (not in this example) to make sure players are correctly positioned. So its technically more than 3 packets but somewhere in the order of 5-20 depending on the distance between move/stop actions but still far fewer than normal multiplayer associated variables

  • Ok i got it. Its:

    On peer created - set peerid to multplayer.peerid (make that person their name)

    IMPORTANT:Setting the scroll behavior to "disabled" on the ability window for that object ahead of time we then go.

    Peerid=Multiplayer.MyID (when player is a player) *Enable local input prediction for Peer

    and

    Set scrollto Enabled for that peer.

    Its what you were saying grandbrinus. Thanks it works now!

    Step 1 of 50 done.. lol

  • troublesum

    Can you please provide a link to the rex moveto plugin?

    I tried to download this one But it provides the following errors on launching your example

    "Found 'GetPluginSettings' global, but it is not a function"

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)