Animation State for "Other" in Multiplayer

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.

this.app.on(‘otherwalk’+this.id, this.keyDown, this);

AvatarAnimationOther.prototype.keyDown = function (e) {
this.setState(‘walk’);
console.log(‘detected walk’);
};

NO LUCK on sending the FIRE using the text+id
Is my logic wrong? , i`m i missing something? Do you have any ideas?

Thanks a lot guys. This will be a grear help-.

Hi @Sasa_Olmedo,

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.

You could also use the current animation of the entity and emit it along with the position.

var currentanimation = Entity.animation.data.currrAnim;

Got it from here:

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

1 Like

Yes, exactly, each state update that is required to be viewed by the other users has to be sent and received accordingly.

COOL, im trying now, ill send the link when done

2 Likes

I’ve implemented this in a recent project. You can come around and take a look

https://playcanvas.com/editor/project/730127

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

1 Like

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);
}
};
1 Like

how did you get the animation update to work?