Finally, It works
@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
Your new project is using socket.io v3
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
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.
thank you
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.
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);
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