setDrag and collideWorldBounds dont work

When I follow the authoritative multiplayer tutorial here: https://phasertutorials.com/creating-a-simple-multiplayer-game-in-phaser-3-with-an-authoritative-server-part-2/
Everything works fine except the setDrag which has no effect whatsoever, and even the collideWorldBounds doesn’t work which I added by myself.

function addPlayer(self, playerInfo) {
   const player = self.physics.add.image(playerInfo.x, playerInfo.y, 'ship').setOrigin(0.5, 0.5).setDisplaySize(53, 40);
   player.setDrag(100);
   player.body.collideWorldBounds(true);
   player.setAngularDrag(100);
   player.setMaxVelocity(200);
   player.playerId = playerInfo.playerId;
   self.players.add(player);
}

Are you sending position or velocity?

The client sends an input request, on the server phaser is running in headless mode and applies velocity based on the input received and then sends the new position back to the client(This happens every frame). setDrag is also on the server side.

I’ve never done server stuff but I remember reading here (I can’t for the life of me find it but you might be able to) that you need to send velocity instead of position to the server.

Fixed it by doing:

self.players.getChildren().forEach((player) => {
    player.setDrag(1000);
    player.body.collideWorldBounds = true;
});
1 Like