Hi @Leonidas not yet, i was able to set up the server and seems players are logged in correctly, but i don’t see them in game, seems there must be an error somewhere.
this is my network.js file
var Network = pc.createScript('network');
Network.id = null;
Network.socket = null;
// initialize code called once per entity
Network.prototype.initialize = function() {
this.player = this.app.root.findByName ('Player');
this.other = this.app.root.findByName ('Other');
this.socket = io.connect('https://skillful-amenable-sky.glitch.me');
this.socket.emit ('initialize');
var socket = this.socket;
Network.socket= socket;
var self = this;
socket.on ('playerData', function (data) {
self.initializePlayers (data);
});
socket.on ('playerJoined', function (data) {
self.addPlayer (data);
});
socket.on ('playerMoved', function (data) {
self.movePlayer (data);
});
};
// update code called every frame
Network.prototype.update = function(dt) {
this.updatePosition ();
};
Network.prototype.initializePlayers = function (data) {
this.players = data.players;
this.id = data.id;
for(var id in this.players){
if(id != this.id){
this.players[id].entity = this.createPlayerEntity(this.players[id]);
}
}
this.initialized = true;
console.log('initialized');
};
Network.prototype.createPlayerEntity = function (data) {
var newPlayer = this.other.clone ();
// Create a new player entity.
newPlayer.enabled = true;
// Enable the newly created player.
this.other.getParent().addChild (newPlayer);
// Add the entity to the entity hierarchy.
if (data)
newPlayer.rigidbody.teleport (data.x, data.y, data.z);
// If a location was given, teleport the new entity to the position of the connected player.
return newPlayer;
// Return the new entity.
};
Network.prototype.addPlayer = function (data) {
this.players[data.id] = data;
this.players[data.id].entity = this.createPlayerEntity(data);
};
Network.prototype.movePlayer = function (data) {
if (this.initialized)
this.players[data.id].entity.rigidbody.teleport (data.x, data.y, data.z);
};
Network.prototype.updatePosition = function () {
if (this.initialized) {
var pos = this.player.getPosition ();
this.socket.emit ('positionUpdate', {id: this.id, x: pos.x, y: pos.y, z: pos.z});
}
};
// swap method called for script hot-reloading
// inherit your script state here
// Network.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/