1
\$\begingroup\$

I am trying to make a fighting game where two characters are fighting with hands or can have some weapon in their hands. It's a multiplayer game targeting initially for mobile devices. In Game, there would be some animation and when that weapon hit other character body, its health will decrease.

I have two different updates implemented. One is Fixed update which calls after every 100ms and all game logic is implemented there and other update is for drawing, running at 60 fps. Now when two players are fighting and one player is animating to hit other, I need to show others player's decrease of health at the time of hit. Now as drawing update is different, I got a hit event in an update but When should I have to decrease the health?

As my all game logic is running in fixed update, I am updating characters health in fixed update and decide whether it's still alive or dead but due to this, on screen, it shows some delay in decreasing health. I want to know am I doing something wrong? What is the standard way to achieve this?

Thanks

\$\endgroup\$
  • \$\begingroup\$ 10 fixed updates per second is a very low rate by typical game standards. May I ask why you've chosen to go this low? Even with some amount of prediction, input latency may be hard to hide at this frequency. \$\endgroup\$ – DMGregory Dec 12 '17 at 8:15
  • \$\begingroup\$ Well, I have read a lot of articles where in almost all multiplayer games, fixed updates used to be as low as 5 fps. \$\endgroup\$ – LebRon Dec 12 '17 at 8:57
  • \$\begingroup\$ So do you have network communication with a server in the mix here? If so, that might be important to include in your question. Different latency-hiding techniques may apply. \$\endgroup\$ – DMGregory Dec 12 '17 at 9:12
  • \$\begingroup\$ thanks, I have added that too. So there are some latency-hiding techniques. Can you please share some knowledge on latency-hiding techniques, that would be very helpful. \$\endgroup\$ – LebRon Dec 12 '17 at 9:23
  • \$\begingroup\$ I'm pretty sure that's not true. Most games use 50 or 20 frames per second. \$\endgroup\$ – Bálint Dec 12 '17 at 9:24
1
\$\begingroup\$

First you need to assign the authoritative simulation. Who decides a score?

If you have a server and two clients, the server would be authoritative of course, and would be running the simulation. So the health of both players is recorded by the server.

If your game is peer-to-peer, it is trickier. Even if we ignore the fact of hacked clients. Do both peers run a simulation? Typically, yes. If so, how are differences resolved?

Consider this sequence of events:

timestamp T0

  • Player A presses the "Jab" button.
  • Client A starts "Jab" animation.
  • Client A sends "Jab" event to client B.

timestamp T1

  • Client B presses the "Block" button.
  • Client B starts the "Block" animation.
  • Client B sends "Block" event to client A.

timestamp T2

  • Client A ends the "Jab" animation.
  • Client A deals damage to player B, as A is still unaware of the block.

timestamp T3

  • Client A receives the "Block" event from B.

timestamp T4

  • Client B receives the "Jab" event from B, and decides there is no damage dealt, because of the block.

Now one clients thinks: "A Hit!" and the other client thinks: "No Hit!"

As you see, Online Multi Player is one big can of worms.

If your animation times are always longer than the latency of the network, it would make your life easier of course. But even then you would need to cancel the effect of a Block, even though its animation has played half-way through, if a Jab event is received.

Personally I've made an online tank game using peer-2-peer with a local simulation on each peer. The simulations on the clients unavoidably differ slightly. To resolve hits, I decided that if the scoring player's simulation shows a hit, it overrides what the victim's simulation says.

PS: With multiple clients, you could also make them asymmetric and have one run a simulation, and the other just plays back the results. This makes for a bad user experience of course, as the player running the sim is at a huge advantage with a 0ms latency.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.