Hi!
I’m trying to make a racing game in meteor. Every player controls a character, and presses on the spacebar to run. The position of all the other runners is displayed on the screen of every client.
on the code side, i’ve got a collection with a player object for every client, with a posX variable which is used in a helper to generate CSS, and is updated every time someone presses on the spacebar.
I have a problem though : in most cases, during the race, as updates on the position of every player are being made at a very fast pace, every single client sees himself/herself as being ahead, even though that’s obviously not possible. At the very end of the race, there is a visual glitch as all the other runners suddenly rush forward to join the ending line. It looks like this :
it’s as if meteor was overwhelmed and decided to take care of all the local updates made by the player before deciding what to do with all the updates made by the other players. Is this the normal behaviour of Meteor? What strategy should i use to address this problem? Am i trying to use the wrong technology to make my game, where updates must be replicated on every client at a very fast pace? (say, 10 times per second for a fast player * 30 players maximum).
my method looks something like this, on the client side :
(javascript)
$(document.body).on(‘keyup’, function(e){
_posX = parseInt(Bonhomme.find({_id:playerId}).fetch()[0].posX)
Bonhomme.update(playerId, {$set:{“posX”:_posX+1}
}
(html)
{{#each runner}}
{{/each}}
i’m using meteor 1.4.2.3 and the game is intended to be used over a local area network rather than over the internet.
thank you for your insights and thank you for your contributions to this great framework!
samuel
PS. you can even try it out on the web, although it might not be practical to play on your own. (altough you can open several tabs & click on “autorun”)
http://sympo.shh.ovh/covid19/200 (the last part of the URL is the number of milliseconds between each simulated keydown)
PS. disclaimer : i learnt to use meteor in art school, so my javascript skills are meh! but i’m enjoying meteor since '2015.