Need help making an online game

Finally, It works :smiley:

@Leonidas it didn’t work for me but I don’t understand why the original code works HERE but not HERE

The server code is different between the two

Your original is using socket.io v2 https://glitch.com/edit/#!/bg-william-co-2?path=package.json%3A15%3A4

image

Your new project is using socket.io v3


image

And therefore needs CORS to be setup properly on Glitch as shown in the Multiplayer tutorial
https://developer.playcanvas.com/en/tutorials/real-time-multiplayer/

Which was mentioned in an earlier reply here: This is weird i need help

1 Like

@yaustar I fixed it and it still didn’t work.

As you have installed the v3 package already, it won’t revert to a v2 package as it’s older. Get rid of the ^ to force it to install v2.

@yaustar when I loaded up the scene I had the what the other what the other player is supposed to be on my waist.

@yaustar Instead of using the other player’s pos it is using mine.
do you know how I could fix this?

I’ve fixed the project and glitch in forks to get the two connected to each other.

https://playcanvas.com/editor/scene/1098063

1 Like

thank you

@yaustar for some reason when I imported the code into my project it didn’t work

Please check all steps in the updated multiplayer tutorial to ensure that you have everything. It’s not just scripts, there are project settings to be changed too.

@yaustar thank you I just had to use the new setting.

@yaustar do you know how I could get it to match rotation as well?

Hi @WilliamBoersma31,

You will have to network (send and receive) the rotation of the player as well.

If your player rotates on a certain axis, send that angle only.

Example code:

// on updatePosition
var angleY = this.player.getEulerAngles().y;
Network.socket.emit('positionUpdate', {id: Network.id, x: pos.x, y: pos.y, z: pos.z, rotY: angleY});
// on movePlayer
this.players[data.id].entity.rigidbody.teleport(data.x, data.y, data.z, 0, data.rotY, 0);

@Leonidas wouldn’t I have to edit the code on the server?

Yes, you will have to edit the following part of the server.js file:

        socket.on ('positionUpdate', function (data) {
                if(!players[data.id]) return;
                players[data.id].x = data.x;
                players[data.id].y = data.y;
                players[data.id].z = data.z;
                players[data.id].rotY = data.rotY;

            socket.broadcast.emit ('playerMoved', data);
        });

ok thank you

Hey @Leonidas can you help me a little bit more?
I keep getting errors whenever I start the scene and it says that
var rot = this.PCOLLSION.getRotation();
is not a function

Hmm, doing a quick search in the tutorial project I don’t see anywhere getRotation() being called.

On what line do you see that?

Oh I see it’s getEularAngles not getRotation thanks

1 Like