Hello world! I’m currently working on my multiplayer game using BabylonJS and Colyseus and I faced an issue about the animation system. My objective is to have multiple people controlling the exact same player. A the moment, when the player collides (this.player.hasCollided), it triggers a method call die(). I can see the message isDead on all sessions in the console. However, the animation is only trigger on the focused session (the one which causes the collision).
I find it strange that the method die() is triggered everywhere, but only trigger on one. Now, if comment this condition : (this.player.hasCollided != change.value)
, the player is animated everyhere. I would like to animate the player while keeping this condition in all sessions…
Do you have any idea of what’s my issue? Thanks
class App:
this.room.state.players.onAdd = (player) => {
player.onChange = (changes) => {
changes.forEach((change) => {
switch (change.field) {
case 'hasCollided':
if (this.player.hasCollided != change.value) {
this.player.hasCollided = change.value;
if (this.player.hasCollided) {
this.isGameEnd = true;
this.setEndScreen(false);
this.player.die();
}
}
break;
}
});
};
};
class Player:
public die(): void {
console.log("isDead");
this.sprite.playAnimation(3, 4, false, 60, () => {
this.sprite.playAnimation(5, 7, true, 60);
});
}