https://docs.phaser.io/api-documentation/class/physics-arcade-world
You're absolutely right! In a multiplayer setting, directly adjusting objects on the screen can lead to inconsistencies due to network latency, differing client states, and other issues. To resolve this, using a physics space (often referred to as a "simulation" or "world" state) to handle the authoritative logic and movement makes things much more predictable and synchronized. Here’s a breakdown of how you can structure this:
- Physics Space (Simulation): This is the authoritative "truth" of the game. All changes to object positions, velocities, and other states (health, status, etc.) happen here. Think of it as a snapshot of the game state that updates according to both local and network inputs.
- Rendering Layer: The visual representation of the objects is based on interpolating between past and current physics states to smooth out any discrepancies caused by lag or packet loss.