Babylon + Colyseus - Issue with the animation system

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

Hi @Rangerz132,
I don’t know the Colyseus at all so I can be terribly wrong but from what I understand the code try check this in the die () method → console.log("isDead", this)
My guess is that i’s pointing to other objects on not focused sessions.
If so I think you will need to broadcast the information about which player died to all other players.

3 Likes

I’m not familiar with Coliseus. But assuming the other way around

  1. Assume that b dies when A touches B.
  2. B executes die()
    When the above conditions are satisfied, check the following
  3. When A kills B, do other users also execute the death of user B?
  4. When B executes die(), is it in a state where no other animation or die() can be executed?
  5. After the last die() is received, another event is received so that it is ignored as soon as die() is
    executed?
1 Like