- Home /
Networking: fast firing weapons?
Is there any trick to reduce number of packets sent when firing a fast weapon like machine gun or flamethrower? For example how does TF2 handle theirs?
Sure - simulate the firing on all clients and only send the started and ended firing commands to the other players would be one way. Are you actually instantiating projectiles?
yea I instantiate new projectile every 100 milliseconds. I suppose precision doesn't matter in this case so every client can instatiate these projectiles independently only based on start/end fire events. But how would I send correct damage then? I am using something similar to a P2P model, i.e. whoever fires the gun calculates the damage (clientside) and sends it to others. So in my case I would still need to spam packets but for damage? Or is there a nice trick to group them together?
Answer by whydoidoit · Oct 13, 2012 at 08:50 AM
So send - begin fire, end fire events to all the clients and use them for the simulation.
On the firing client - add your damage packet to a List<DamagePacket> and then send them all 5 times a second or something. It's actually quite possible to turn that list into a string and fire it across the network. My extension to RPC here has the code to convert a serializable class to a string and then reconstitute it on the far end. In other words you can RPC to methods with parameters that are your own custom serializable classes.
Your answer
Follow this Question
Related Questions
Connect game through cable 0 Answers
Network spawning 1 Answer
Prevent players from using Network.Destroy() 3 Answers
OnSerializeNetworkView multiple variables 1 Answer
On Network GameObject Movment and Rotation Problem. 1 Answer