How to synchronize the coordinates of characters in real-time action battle games?

.
@Bink
@joshtynjala
.
How to synchronize the coordinates of characters in real-time action battle games?
.
For example, player 1 and player 2 are fighting in their own homes via the Internet, and player 1 operates his role p1 to move to player 2’s role p2. How can player 2 see that player 1 operates p1 to move to his role?
.
I have come up with a method, which is to continuously broadcast the position of P1, and then player 2 synchronizes the position of P1. However, I think this is not feasible because if there is network delay, player 2 will not move when they see P1 because they have not received data from P1 due to network delay
.
Then I came up with another method,
That is to use ‘Tween’ to move ‘p1’,
Because using ‘Tween’, even with network latency, Player 2 will still see P1 constantly moving. Is this method feasible? Thank you all.
.

I think you will want to investigate a game server such as Colyseus. It can “automatically synchronize the state from the server with connected clients.”

@785597448, I’d perhaps back-peddle a bit as there’s quite a bit to consider when it comes to handling network based multiplayer.

Based on what you’ve described of your game project to date, can we assume the following?

  1. You are referring to a HTML5 multiplayer game.
  2. Therefore a central server is required, as HTML5 clients can not directly connect to one another.
  3. You would be using WebSockets to communicate (openfl.net.Socket implements the browser WebSocket under the HTML5/JS target).

If these assumptions are correct, then a central server will need to be involved in some way. There are two key ways you could use that server:

  1. As a basic WebSocket relay between connected clients of specific multiplayer sessions / rooms. The server remains lightweight and simple, with its only purpose to be aware of unique multiplayer sessions / rooms, and sanitise and relay data between all clients within specific multiplayer sessions with minimal handling. Clients are then largely responsible for managing the multiplayer code, such as identifying incoming data, matchmaking and lobbies, connection handling, latency and deltas (change updates).
  2. The central server manages the multiplayer sessions. This is the sort of solution Colyseus that @Confidant mentioned, provides. It’s a good option because it’s supported with Haxe libraries, that provide some scaffolding for you. There is a demo project here. You’re not limited to that though, you could theoretically use anything that supports WebSockets as well, such as Nakama, but you’ll need to build your own scaffolding.