How do I scroll camera on each player in multiplayer?

Get help using Construct 2

Post » Thu May 22, 2014 4:49 pm

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! :?
B
7
S
1
Posts: 10
Reputation: 1,196

Post » Fri May 23, 2014 10:34 pm

Did you figure anything out. I have got the exact same issue. Spent days trying to solve it. Still haven't!
B
17
S
2
Posts: 29
Reputation: 779

Post » Fri May 23, 2014 10:40 pm

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 :)

Untitled.png


Hope this helps..
You do not have the required permissions to view the files attached to this post.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Sat May 24, 2014 1:48 pm

troublesum wrote: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 :)

Untitled.png


Hope this helps..


can you upload CAPX for example ?
B
2
Posts: 6
Reputation: 162

Post » Sat May 24, 2014 9:44 pm

multiplayerExample.capx


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.
You do not have the required permissions to view the files attached to this post.
Last edited by troublesum on Sat May 24, 2014 11:09 pm, edited 5 times in total.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Sat May 24, 2014 10:02 pm

@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.
B
13
S
5
G
1
Posts: 138
Reputation: 2,659

Post » Sat May 24, 2014 10:06 pm

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?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Sat May 24, 2014 10:26 pm

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.
B
13
S
5
G
1
Posts: 138
Reputation: 2,659

Post » Sat May 24, 2014 11:29 pm

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
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Sun May 25, 2014 12:47 am

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
www.herodefense.com
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 10
Reputation: 1,196

Next

Return to How do I....?

Who is online

Users browsing this forum: David181, manujorgo, NECRONOMICRON, rbailey83 and 25 guests