Hi, I have simple scene with two football players and one ball. Players can move across the field and they interact with ball by bouncing. Each player can also kick the ball and this is implemented through computing certain force vector and applying this vector to the ball when player press button. All three objects have RigidBody2D and PhotonTransformView component, Ball has also PhotonRigidBody2DView.
I am currently implementing multiplayer version of this game with Unity and Photon and I´m struggling with some problems regarding kicking. My current implementation looks like this:
1) Compute force vector based on common position of the ball and the player when the ball is close enough
2) If player press kick button and he is close enough to ball to kick:
2a) kicking player requests ownership of the ball gameObject (ownership set to Takeover on ball object)
2b) kicking player sends RPC with final vector to other clients (PhotonTargets.AllViaServer) and the force is applied to the ball
It is working well in 90% of the cases, but sometimes when the player without ball ownership kicks the ball, the ball moves little bit to desired direction and then stops. After this step player gets an ownership and all the other kicks are working well.
Could you please give me some advice regarding my problem? It is really annoying because it is hard to replicate the problem and I don`t know what can cause it.
Also, some more general question - is there some best practice recommendation how to deal with realtime physics-driven ball shared with the players on the scene?
Every advice is welcomed, thanks in advance!
I am currently implementing multiplayer version of this game with Unity and Photon and I´m struggling with some problems regarding kicking. My current implementation looks like this:
1) Compute force vector based on common position of the ball and the player when the ball is close enough
2) If player press kick button and he is close enough to ball to kick:
2a) kicking player requests ownership of the ball gameObject (ownership set to Takeover on ball object)
2b) kicking player sends RPC with final vector to other clients (PhotonTargets.AllViaServer) and the force is applied to the ball
It is working well in 90% of the cases, but sometimes when the player without ball ownership kicks the ball, the ball moves little bit to desired direction and then stops. After this step player gets an ownership and all the other kicks are working well.
Could you please give me some advice regarding my problem? It is really annoying because it is hard to replicate the problem and I don`t know what can cause it.
Also, some more general question - is there some best practice recommendation how to deal with realtime physics-driven ball shared with the players on the scene?
Every advice is welcomed, thanks in advance!