I am working on a game that is fairly simple in scope, but has one fairly complicated aspect. The game revolves around two teams (4-5 players) grabbing/passing/throwing a game ball into opposing goals. I am running into issues with replicating the game ball itself and keeping the action inputs from the players in sync with the game ball with any kind of real world packet lag/effects factored in. It is simulating physics, which I know is very complicated and can only be handled on a case by case basis, but I was wondering if anyone could point me in the right direction for a solution to my issues. If anyone has comments on a better way to handle the interaction with the game ball from the client characters, I am open to all suggestions and would love to hear peoples thoughts and ideas.
Now for a detailed view on my setup so far:
- Client actors walk over to the ball and the ball generates overlap events.
In the begin overlap, the ball actor passes a reference to itself to the character, and sets a flag on the character that indicates to the character that the ball can be picked up
In the end overlap, the ball actor sets the ball reference on the character to null, and sets the character flag from the begin overlap to false, indicating the ball can no longer be picked up.
- On the client character, the character has an input event for pickup, and an input event for throw. Both check for validity of the ball reference and if the ball can be picked up/is currently being carried.
the pickup event calls a function (on the server and locally) using the ball reference in the ball actor class that attaches the ball to a socket in the player’s hand. This function is passed a reference to the character, and the name of the socket to attach to. So, the actual attaching takes place in the ball actor class.
This pickup function in the ball actor class turns off physics and attaches to the character hand socket.
- the throw event calls a function (on the server and locally) using the ball reference to call a function in that class to detach from the socket, reactivate physics and add an impulse to the ball. The function is passed a direction vector that is computed using the camera direction at time of throw.
My issues with this, are if I only call the attach and throw functions on the server, there is an unresponsive lag (as would be expected) for picking up the ball and throwing it. If I call the pickup and throw functions on the server and locally, sometimes the ball will disappear on the client side and be seen jittering around somewhere on the map (usually in the middle) and throwing the ball has the obvious server corrections on the client side.
Any help or guidance would be greatly appreciated. Not really looking for anyone to solve my problems for me, more looking for guidance or a point in the right direction if any of you have run into similar issues or heard of solutions working for other people for similar problems.