On joining room create new actor with specific a role

Alexdg
Alexdg
edited October 28 in JavaScript and TypeScript

Hi, I'm using PhotoEngine JavaScript SDK

I'm creating a game with players and one observer who can join a room. I have these 2 flows:

(1)

ClientA => create a room [A] => create actorA (player) => create new model = 3D character

(2)

ClientB => join room [A] => create actorB (observer) => setCustomProperty('observer', true) => create new model = camera

The problem I'm facing is when ClientB is joining the room [A], clientA has onActorJoin triggered immediately but the custom property 'observer' is false and then it starts to create a new model as a 3D character and I don't want to create a character, as this actor is an observer which should be a camera only for ClientB.


  • What would be the best approach for this use case?
  • How to sync all clients to tell them the new actor who joined is an observer? Or is it possible to avoid to dispatch the event onActorJoin through all the connected clients in the room and keep it happening only for the local client?
  • The other idea I have is not ideal, but I could define a rule for exemple if 2 players are already part of the room, the 3rd one is by default an observer. But I wish I could do something a bit more flexible.


Thank you for your help.

Comments

  • Hi,

    Simply set local player properties before joining or creating a room, just like you do when the client is in the room: client.myActor().setCustomProperty(...).

    Also you can handle subsequent properties change with client.onActorPropertiesChange() callback.

  • Alexdg
    Alexdg
    edited November 8

    I didn't think I could just actually use the client actor directly... Thank you very much Vadim.