How do I target Individual Peer Animations?

0 favourites
  • 3 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Hello everyone, hoping someone has some insight on this.

    I'm working on this multiplayer game that uses the peer system from the Construct multiplayer documentation tutorials. When a new player joins, a peer sprite is created on everyone's screens as expected. All the movement works.

    I am using a separate sprite for the character's animation. So I made it so that when a peer is created, a PlayerAnimation sprite is created with it and gets pinned to it. Only problem was, when testing for whether a peer was facing one direction or another to change the animation, it tested for all the peer sprites at the same time for some reason.

    My fix was to create instance variables on the peer and PlayerAnimation sprite so that they could be individually identified. I made global variables that go up by one every time a peer is created and then sets its instance variable to the respective global variable. So for example, if a second peer is created, it would have an instance variable of 2 (or 1 depending on if you start at 0 or not) and its respective PlayerAnimation sprite would have the same number.

    I then created a for each peer loop that uses Construct's 'pick where' condition and changes the number it's targeting each time it's looped. So each time it loops, it's targeting a peer and PlayerAnimation sprite with a specific instance variable, forcing it to test each character's direction and change its animation individually.

    This is probably not the best way, but I thought for sure it would work. However it seems like the host and peer are not seeing the other's animation. I'm using Chrome and Edge to simulate different computers but maybe that is also interfering.

    This project is for class, any help is much appreciated, thank you!

    Link to the project file: https://cegepheritageqcca-my.sharepoint.com/:u:/g/personal/2159450_cegep-heritage_qc_ca/EcCvhYSZhPRDjbY3mRUUMTcBkeu6_PdA_bneXobCwrUA-w?e=wQXehI

  • Any object with instances that need to be differentiated per peer should have an instance variable to identify it - this is usually what the peerid is used for.

    Animations are not normally synced. All animation should be handled locally on each client. There are a few ways to go about this.

    Cleanest way is to set animations locally based on the change in position or angle of the object (because position/angle is already synced). This works for movement style animations, but not for anything that is based on an input.

    If you have an animation that results from a specific input, the host will need to relay that input to other peers manually so that the other peers can play the correct animation (inputs are normally communicated only from the peer to the host). However it would be silly to send every input of every peer to all the other peers all the time, since most of it is unnecessary information. Instead, the host can send the "state" of any particular peer's animation to all peers. This can be done either with a synced (number) instance variable (probably set on the particular peer's instance) or by sending a message (with the relevant peerid and correct animation state contained).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you for your reply oosyrag! That makes more sense for sure. I've found there isn't much information on these topics but it's pretty interesting.

    I'd briefly thought of being able to send some sort of message containing the animation information, however it's my lack of knowledge of the program or multiplayer in general that stopped me from doing that first so thank you for explaining it to me.

    Fortunately, I've somehow gotten it to work with what I guess you can call a semi-local fix to the problem.

    Okay here it is, I'll try to explain best I can. First, I ditched the PlayerAnimation sprite and simplified everything by just adding the animations onto the Peer sprite. Now there's only one sprite to deal with.

    Next, I again used a for each loop to go through each Peer. Using a global variable PEER_FOREACH that goes up by 1 each loop and resets to 0 when it reaches the number of Peers, I was able to pick every Peer instance individually. This was done by using a condition 'Pick Peer where Peer.IID = PEER_FOREACH'. Since all the characters look the same and have the same animations, I used their IIDs to distinguish them in the moment, because in this case it doesn't matter if the IID changes. What it does do is ensures that if there are 3 players for example, there will always be IIDs of 0, 1, and 2, so the for loop should work no matter what.

    Then, in its subevent, instead of testing for movement like I did before, I used the system getbit(Peer.inputs,(0, 1, 2, or 3)) = 1 to get the inputs from players, as it seemed like testing for direction wasn't working on all of them (wasn't consistent). This left me with animations working across screens, but only for Peers. Every single player that wasn't the host's specific player (Peer instance) had a working animation.

    So after that, the reasoning I came to is that since the host's inputs were being run locally, the other versions of the game were not able to detect its inputs. Idk if this makes sense, but on top of controlling its inputs directly, I added 'set inputs to setbit(Self.inputs, (0 to 3), (0 to 1))' for each of its inputs so that they wouldn't just be local and would then work with my for each loop.

    Not gonna lie I was actually surprised when this worked right away so there's probably something wrong with performance or something now haha.

    Anyways, just happy to get it working, and maybe I did it totally wrong but hopefully this is also useful to someone somehow.

    If it doesn't hold up as I continue to work on the game, I'll be using the method you suggest oosyrag, so thank you again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)