[SOLVED] How to do multiplayer?

@poliveira Can you give me the link to the updated Photon tutorial? And about the Colyseus I was not able to connect to the server for some reason i might not have followed the tutorial properly.

The Photon page has been updated here: Real-time Multiplayer with Photon | Learn PlayCanvas

If you are running into issues with Colyseus, check this or other threads around it: [SOLVED] Colyseus is not working with Playcanvas - MultiPlayer Demo not work

@Leonidas @yaustar @poliveira I was trying Colyseus again and setup server the locally. I tried the first command “npm init colyseus-app ./playcanvas-demo-server” It asks me to select a template when I select TypeScript(recomended) it says the following error

Is the ./playcanvas-demo-server folder empty (also empty of hidden files and folders)? If not, delete it’s contents and start again

1 Like

@yaustar the folder is empty still getting this error

Including hidden files and folders? Might be easier just to delete the ./playcanvas-demo-server folder itself

Yea i have tried to do that deleted the folder itself but and try that command again but still its shows the error

I’ve just tried the command and it works fine on my end :thinking:

A bit difficult to diagnose without being at your computer I’m afraid

I am not sure what’s going on here :smiley:. I tried deleting the folder many times. Can you confirm one thing do we have to do this on Administratoe side of pc?

@Vivek_Chaini It looks like you open the command prompt in your users directory on windows. This is the default when you open a command prompt. You could try the following. Create a directory under your C: drive. Open a command prompt which will default to C:\Users…> Navigate to root. Then cd to your newly created directory. If npm is installed correctly you can execute the the npm init command as shown above here. Also, there is a log that is generated on failure. It would be nice to see that as well.


I tried what you said still not working here is the log @Tirk182

@Vivek_Chaini It looks like you are still using the C:\Users…> location. Do you have a log from the other location. Also,

npm init colyseus-app ./playcanvas-demo-server <<<You could change this name. It’s just the folder for your build.

1 Like

@Tirk182 This is not wroking as I dont have access to certain folders. However I am trying to do multiplayer using Photon and its working fine. But the players are showing very weird behaviours(like when player1 moves we can see that another player2 is following player1 whereas player2 is not moving at all there is some problem with the movement) Can anyone suggest what is wrong here in this project PlayCanvas | HTML5 Game Engine and how I can fix it?
Here i’m not using pointAndClick instead im using fpscontroller script @yaustar @Leonidas

@Vivek_Chaini I ran your code that you have in the link above. Seemed to handle FPS controller fine. How are you launching the second instance of the game? Here are the steps I used to test it out on the same machine.

1.) Loaded project above in edit mode.
2.) Clicked launch and created a new room and moved my player to another point on the plane.
3.) I right clicked on the Editor tab in my browser and selected duplicate.
4.) I clicked on the duplicated tab which shows the editor.
5.) Clicked launch and then joined existing room.

I found that when I was moving one player it was best to escape out of that game before I went to the other tab. There was something that was a little fishy about the position of each player at times but they did not follow each other around.

This is what I see on FPSPlayer entity.

Maybe there is something going wrong here.

1 Like

I did the same thing what you did and also another user joined from different machine the movement was jittery(if we see from player1 perspective player2 movement is jittery and vice versa). And in the FPSplayer entity if you’re talking about the script its disabled. I am not able to figure out what’s going on in project.

@Vivek_Chaini I think I was able to see the issue. The FPS camera was not set inside the player. Here is your original.


Your camera is set in root which is giving you just an overall picture outside the player. I deleted the camera in root and added a new camera inside the FPSPlayer.

I then made the following change to FPSPlayer.

Let me know if this fixes it for you. Actually there is also some other issues with player. You probably have to make the same changes to it as well @poliveira? This is what I did to player that is disabled.

The point and click script needs to be deleted so the players don’t join each other when they get close. This will be active in your Root.


@Tirk182 In the fpscontroller script it creates camera automatically and i tried what you suggested its not working and we cant put the fpscontroller.js script in each player because then we will be able to control other player from our controls and same for the other player also. player.js script is needed to see realtime updates of other players if we remove other player just join the room and they will be moving around but we wont be able to see where they are going(i hope you get it). And i think there something to do with the position of the players which is done by player.js script PlayCanvas | HTML5 Game Engine

@Vivek_Chaini I will have to have a look much later today. Here is a link to my fork of your original.
Overview | Dashboard | PhoVDS | PlayCanvas | 3D HTML5 & WebGL Game Engine

Just a quick glance you do not have a camera object associated under FPSPlayer like the example I showed above.

Maybe someone else in the meantime could have a look. I think it’s very close. I just did not have enough time this morning. @Leonidas

The issue is that in the Player Template (the used for other networked players) also had the player.js script. The original tutorial didn’t have this.

This meant that networked players on one client were also sending events to update it’s position leading to a circular loop of everyone updating everyone else instead of just their own position.

Fixed project https://playcanvas.com/project/989525


Thanks its working fine it was just because of the player script attached to the prefab. Thanks for the support @yaustar i really appreaciate it.