I am using Box2D for physics on the server side. Player position is updated on the server, so there is nothing the client can do except give input.
But running game in Chrome only, the player moves faster as compared to running in Firefox only.
If running in both browsers (one player in each browser), then the game in both browsers runs at the speed at which it runs in Chrome.
Using this update loop:
function update() {
for(let p of players){
if(p.dead) continue ;
p.keyEvents();
aabb.lowerBound.Set( p.body.GetPosition().x-p.s_w/(2*scale),p.body.GetPosition().y-p.s_h/(2*scale) );//top left
aabb.upperBound.Set( p.body.GetPosition().x+p.s_w/(2*scale),p.body.GetPosition().y+p.s_h/(2*scale) );//bottom right
world.QueryAABB( ReportFixture , aabb , p.id );
p.socket.emit('players',foundPlayers);
foundBodies.players=[];
}
world.Step(
1 / 60 //frame-rate
, 8 //velocity iterations
, 3 //position iterations
);
if(deletePlayerIds.length>0){
deletePlayer();
}
world.ClearForces();
}
setInterval(update, 1000/60);//to call update loop
I have read that for Box2D there is no need to apply a delta.
What could be the reason for different speeds, and how it can be resolved?