1
\$\begingroup\$

So I'm trying to prototype a primitive 1v1 fighting game where the goal is to push the opponent off of the platform rather than actually fight. This is working great in a local multiplayer setup using a physics material on the "belly" of the Rigidbody2d players (the circle collider gameobject nested inside of the square gameobject has the bouncy material).

But I'm toying with the idea of making it a network game and it seems the physics material doesn't get communicated too well over the Photon Realtime connections?

Here is a video showing how it seems like sometimes the position is updated but sometimes a player runs into another player and its like a brick wall:

https://i.stack.imgur.com/cXYrN.jpg

Any ideas of what to try or if this is even possible?

A bit about how things are currently setup: Each player object has the nested collider with a high bounciness material on it. Each player moves via the Rigidbody2D component via

.AddForce(direction * Speed);

I have a Photon View component on the player prefab and a Photon Rigibody 2D View component that is checked to Synchronize Velocity and Angular Velocity, as well as a Photon Transform View component synchronizing Position. Both the transform view and Rigidbody2dView are Observed Components in the Photon View.

I also found a script someone posted where they were manually sending the position/velocity data via OnPhotonSerializeView() I've tried adding that script and making that observable as well, but no luck, but it looks something like this:

 public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting)
            {
                //We own this player: send the others our data
                stream.SendNext(transform.position);
                stream.SendNext(transform.rotation);
                stream.SendNext(r.velocity);
                stream.SendNext(r.angularVelocity);
            }
            else
            {
                //Network player, receive data
                latestPos = (Vector3)stream.ReceiveNext();
                latestRot = (Quaternion)stream.ReceiveNext();
                velocity = (Vector2)stream.ReceiveNext();
                angularVelocity = (float)stream.ReceiveNext();

                valuesReceived = true;
            }
        }

        // Update is called once per frame
        void Update()
        {
            if (!photonView.IsMine && valuesReceived)
            {
                //Update Object position and Rigidbody parameters
                transform.position = Vector3.Lerp(transform.position, latestPos, Time.deltaTime * 5);
                transform.rotation = Quaternion.Lerp(transform.rotation, latestRot, Time.deltaTime * 5);
                r.velocity = velocity;
                r.angularVelocity = angularVelocity;
            }
        }
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I would try to assume that the reason for this is that the new coordinates of the second player's movement are transferred from the master to the client a little bit later than the player on the client actually collides master's player on his side. The possible solution to the problem depends on many factors and may be different. In my case, I divided the objects into 2 parts: the Visual part and the Collider. The Collider of the players on the master is always a little ahead of its Visible part to make a collision and send new coordinates to the client as soon as possible (but it shouldn't be too large to be noticeable to the player eyes). It will take some work to adjust it properly: to split objects into 2 parts (I did it programmatically) and work with it in your custom OnPhotonSerializeView where you should move your Colliders faster than your Visual part (which should be moved smoothly).

\$\endgroup\$
2
  • \$\begingroup\$ That's an interesting idea and I'll try to consider that. One thing that is still kind of unknown to me (As a newer user to Photon Engine) is how to actually work with a Master. I followed the PUN 2 documentation to create what I have so far and it seems like it's not server authoritative. I think if I did that it would be better, but not sure. \$\endgroup\$ Aug 20, 2019 at 14:17
  • \$\begingroup\$ It depends on the logic you put into it. In my project it works as authoritative for some mechanics (for example for moving physical objects). Of course, this is not a classic authoritative server in a sense that it works on the computer of one of the players. \$\endgroup\$
    – Serg
    Aug 20, 2019 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .