Hi, im trying to make a multiplayer and so far, so good.
But my problem comes, when i what to see the animation state from the OTHER avatar. Meaning, as you can see on the live link, that everything works great, but when i try to send an animation state change to the OTHER according to the PLAYER movement, every OTHER in the scene moves, because of the entity id, or name, or index.
I have tried to solve this, by detecting the ID assigned to each user, and having an event fire on the app, using that unique ID, so my PLAYER dosent move all of the OTHERS, but only my own OTHER. But no luck.
Your logic is correct, using a unique ID to drive animation/movement state updates.
But are you sure you are networking both the movement and the animations? Are those animation events getting broadcasted through the network layer?
Edit: normally networking each animation required can consume too much bandwidth, so another trick is to try and infer the correct animation depending on the current movement:
e.g. going forward -> play the forward animation
jumping -> start playing the jump animation
etc.
WOOOWWWWW NO! I`m not networking the movements, i thought that they were capture inside de scene.
So…
If I want my PLAYER to send data to my OTHER it has to go through the Network.js layer?
Ill try this rigth now
Thank a lot, I haven’t thought of that
Essentialy I check if currAnim has changed every frame on the client side. If it has, the player sends it’s Entity.animation.data.currrAnim to the server. Then, every other player gets that and applies the animation to the players’s model that matches with the Id
OK guys i was abble to get the animation state by firing an event on the position change througth the server.js on the network, but i cant get the rotation right, take a look
if you have any tips about the rotation, i dont know what method to use, setRotation, setEulersAngles or setLocalRotation or setLocalEulersAngels.
Network.prototype.rotatePlayer = function (data) {
if (this.initialized && !this.players[data.id].deleted) {
var rot = new pc.Vec3(data.x, data.y, data.z);
this.players[data.id].entity.setLocalEulerAngles(rot);
}
};
I have the data from the server, that ok, but no luck on rotating my OTHER on realtime
Eulers are rather impredictable, I wouldn’t recomend using them… Things tend to flip their axis (known as gimbal lock) and it’s most likely that you won’t get the result you want.
In this case, I think quaternions are much more reliable.
As a rule of thumb, I’d use Eulers to rotate things by a specific amount of degrees, and Quats for general orientation.
//First emit the player's rotation
Network.prototype.updatePosition = function () {
if (this.initialized) {
var pos = this.player.getPosition();
var rot = this.entity.getRotation();
this.socket.emit ('positionUpdate', {id: this.id, x: pos.x, y: pos.y, z: pos.z, rot: rot});
}
};
//then use data from other players
Network.prototype.rotatePlayer = function (data) {
if (this.initialized && !this.players[data.id].deleted) {
var rot = new pc.Quat(data.rot.x, data.rot.y, data.rot.z, data.rot.w);
this.players[data.id].entity.setRotation(rot);
}
};