Getting Client Bullets onto the Server
When working with networking, a whole slew of new problems are introduced to the thought process of programming. Shooting is a great example of this. In a single player game, you can put the implementation anywhere you like and not have to worry about it not functioning correctly. You could put the shooting implementation in the gun or the player. However, when you add networking, you add a whole new headache.
The problem was that player bullets were only being created on the individual client's sides. Simple enough. However, the issue lied with who was creating the bullets. The way we have our game set up, the player picks up guns off the ground as they go. These guns were created in the level and are owned by the server. Therefore, any action that would want to be replicated to the server gets shot down due to the issue of ownership. After tinkering with the pickup system for some time, I opted to take the actual shooting functionality and move it to the player, which is guaranteed to be owned by the client.
In order to do this without causing too much of a fuss, I created a component and populated it with all the variables and functions found in the basic gun. Then, I removed all the gun stat variables and added a current gun object reference that'd be changed whenever the player switched weapons.This object reference would hold all the stats allowing for the component to be filled with less clutter. In fact, the component only needed so much implementation before it was fully functional.
After that, I had to take the parts of the player that relied on the original gun implementation and modify them to suit the needs of the new component. After substitution of old implementation for new implementation, the shooting is now successfully able to be replicated to the server.
Comments
Post a Comment