gomedev Posted March 8, 2016 Share Posted March 8, 2016 So for singleplayer games, entity movement is an easy task. You just increase the player x/y values or add some velocity. Now, in multiplayer, it's not viable to send that many packets per second, so I send movement coordinates every 100ms. RemotePlayer.prototype.update = function () { if (this.player.x !== this.lastPosition.x || this.player.y !== this.lastPosition.y) { this.player.play('move') console.log('playing move animation') This doesn't work. Animation doesn't play, ever, although I get the console messages of "playing move animation". But more importantly, the remote player is seen as a teleporting entity. Any advice? My idea is, instead of teleporting it, translate it from point A to B. But Phaser offers no translation, right? I could use velocities for that, but since I'm sending a movement packet once every 100 seconds, I would have to write a very complex interpolation logic, and I don't see it as necessary since my stage are tile maps. Link to comment Share on other sites More sharing options...
ShimShamSam Posted March 8, 2016 Share Posted March 8, 2016 Take a look at http://phaser.io/docs/2.4.4/Phaser.Tween.html Link to comment Share on other sites More sharing options...
eXilz Posted March 8, 2016 Share Posted March 8, 2016 I haven't actually tackled this sort of thing with Phaser but a common thing to do is to send a packet with the 'intent' of the movement. It would be the direction and the velocity. So you just have to send another packet once this changes and each client will figure out the new positions by itself. Of course, there will be a little difference between client A and client B, so you need something to work out these tiny differences. It's actually a lot of work to get this working smoothly, as you might expect. Link to comment Share on other sites More sharing options...
rgk Posted March 9, 2016 Share Posted March 9, 2016 Honestly you could send position and velocity data every update loop (its not that intense on the server I do it with my game), next problem is your playing the animation every time instead of moving the frame forward, try using next. Link to comment Share on other sites More sharing options...
kalevski Posted March 9, 2016 Share Posted March 9, 2016 You can send detailed info (moving path and timeline events) every 100ms for all your units and get data from server for other. In this way other units will be 100ms after your units. Spend more time on finding balance between data size and sync rate. Link to comment Share on other sites More sharing options...
mattstyles Posted March 9, 2016 Share Posted March 9, 2016 Sending new data periodically is fine and will help your bandwidth anyway. You'll need some client-side interpolation code. The server simply says move to point X, it is up to the client to decide how to move there, so long as point X is not too far away then its all good. If it is further away and requires something like path-finding then you just need to make sure that your path-finding algorithm is deterministic so that server and client can both predict what is happening (seriously, I wouldnt worry about this at the moment, it doesnt sound like you'll run foul of stuff like this yet). There are a couple of ways of skinning this cat, none of them are particularly simple. Multiplayer is hard. In your case it sounds like some interpolation/translation code would do the trick so that your units move to a destination rather than teleport. You'll have to consider that this movement takes some time, it might not be much but it'll be longer than teleportation. Link to comment Share on other sites More sharing options...
Recommended Posts