Jump to content
  • Advertisement
Sign in to follow this  
Butabee

Attack synchronization

This topic is 2952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making an online action game but I'm having a problem with attack synchronization.

What I'm doing is sending an attack message to the server and playing the attack animation immediately on the client. The attack message and animation is played only if the attack recover time is up.

When the server receives the message I play the animation if the attack recover time is up.

but sometimes the attack animation doesn't play on the server. It looks like a timing issue. The attack recover time isn't up when the message is received.

So I was wondering if I should instead send an attack message to the server without playing the animation on the client then send a message back to the client if the attack goes off on the server and then play the animation on the client.

Or is there a better way to do it?

Share this post


Link to post
Share on other sites
Advertisement
you should propably try to figure out why the attack timers are out of sync. what you can do is give it some "slack" on the server - to compensate for the lag that may caused the timers to go out of sync in the first place.

I dont think it is a good idea to wait for server to respond before you do the attack. It will feel very unresponsive. When you press a key you want the visuals to respond immediatly.

There was a good article on gamasutra about it called "Measuring Responsiveness in Video Games". It seems that i cant access the page right now, but google should have it buffered.

Share this post


Link to post
Share on other sites
You're right I don't want the gameplay to feel sluggish.

I initially had a little slack on the attack timer but I guess it wasn't enough, I added a little more and it seems to be working fine now.

the attack cooldown on the server is now (attackcooldown- packet RTT * 2).

I'm just a little worried about it because players might be able to modify their client to send more attack messages than usual and they might be able to attack a little faster.

Share this post


Link to post
Share on other sites
Quote:
but sometimes the attack animation doesn't play on the server. It looks like a timing issue. The attack recover time isn't up when the message is received.

Let's imagine you're discarding messages if they come in too soon. All that needs to happen for this to occur is that the first message took slightly longer to send than the second. So for example, even though the client sent the messages 2 seconds apart, the server could receive them 1.98 seconds apart. You might expect this to happen up to 50% of the time.

So. Don't treat them as attack messages. Treat them as attack requests. It's your job to have the server decide whether a request is reasonable or not, and how and when to fulfill it. Your 'reasonableness' test needs to be tolerant of slight variations while ensuring fairness in the long term.

A simple algorithm for this could be something like:

When an attack request comes in:
Do we already have an attack request queued for this person?
If so, discard this one.
If not, how long ago was this person's last attack
If it was less than the recover time, queue this attack for when the time will expire
Otherwise, handle this attack now (or queue it with 'now' as the time)
Periodically (eg. several times a second), handle all the attack requests on the queue.


This will mean that attack requests that come in a little early will just get delayed until they're due. Attack requests that come in a little late will be handled late. You can fix that by having the attacks all generated server-side, for example.

As an aside though, it sounds like you're changing random stuff and tweaking until things work. Don't do that. If your software is failing to show an animation when you expect it to, you have a problem - either your software is bugged, or you don't really understand what it does. Add logging and debugging until you understand exactly which of those is the case.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!