🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Best method for weapons

Started by
1 comment, last by anjee 23 years ago
Hi, the multiplayer code of my game is now completely perfect, it''s practically impossible to make it smoother than it is now... But now I''m wondering about the weapons. There are a few methods to synchronize them over the internet. 1) Use the timestamp (synced with the server) that is added to the "fire weapon" packet, and then calculate the position where it would be using the heading and speed, and elapsed time since the actual ''firing'' of the weapon. 2) Use the position of the ship of the player that is shooting. So if the player moves fast the weapon will start from the position the player is currently facing. No heading or facing is sent with the packet. The weapons will only move the direction the player was facing. 3) Same as 2 but then do add a heading of the weapon and velocity. But the ship _might_ be facing a different angle when the weapon is fired on other clients, so torpedo''s coming from backwards might be the result. This will only happen though when the update packets of the ship are received earlier than the ''fire'' torpedo packet. What would be the best method in your opinion? Or do you maybe have a completely different one? Thanks, Almar
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
Advertisement
Hi,

I''m currently working on the same problem. I''m working on a twitch style game where there are many weapons available from knives to rocket launchers.

The approach that I am working on at the moment (although not my most favoured method) is to rely on the character syncronisation and always source the weapon fire from them.

Personally I would have prefered to use time stamps and a bit of maths to calculate the path of the projectile and the path of surrounding game characters to she if they would have collided.

But neither time, nor the current state of the game allow for this approach.

It appeares to work well on a LAN where the latencies are low... I have yet to see what happens in the internet world.

I wouldn''t mind chatting more about the methods you have used to do your syncronisation, perhaps you could email me?

Cheers
We use a combo of method 1 and 3 ourselves. Each weapon creation event contains :

a)weapon type
b)unique network id
c)x,y,z position
d)heading,speed
e)time

That''s alot of info, but it will allow you to do several things.

a)buffer weapon events
b)resyncrhonize weapon events if packet arrives late
c)extrapalate where the weapon will be if packet arrives late
d)its accuracy is not dependent upon any other entity

You can compress down the data as much as you need, so it will be around 15 bytes or so.

Though if your willing to lose some accuracy then you could syncrhonize it based upon your entity. An event packet of that nature could proably be compacted to about 5 bytes. Perhaps with these fields

a)event_type
b)entity_id
c)direction
d)time

This method is as only accurate as your entites accuracy. If its off then so will the shots. The time variable could be used to syncrhonize the timming of the shots.

Good Luck

-ddn

This topic is closed to new replies.

Advertisement