Two Colliders of Photon objects are acting like one!

Options
I am developing an Unity game app with PUN. I put two photon objects in the same game room by logging in from 2 devices. Those two objects are the same thing, having a Sphere collider. But, of course, each object is owned by different client.
The problem is that the 2 colliders of those 2 objects are acting like one object. When a collider of an object detects collision, the other collider also detects collision that doesn't happen.
I guess I missed something when I define those objects. What I did is that I put Photon View Script onto the object and
create them by PhotonNetwork.Instantiate. I guess I need a lot more knowledge about Photon.
Please help me. Any advice will be so appreciated.



Comments

  • Hi @AppPop,

    When a collider of an object detects collision, the other collider also detects collision that doesn't happen.


    What exactly do you mean by this? If both objects are colliding with each other, both collider will detect this collision. If you use Unity's OnCollisionEnter callback, you should add a if (!photonView.isMine) return; condition in order to make sure, that the callback only gets processed on the client who owns the object.

    If I misunderstood the problem, please let me know.
  • AppPop
    Options
    Thank you for your comment. I guess I don't understand exactly how PUN works. What I'm saying is like this. Two clients get in the same room with the same player object. One attacks the other. But the attacker detects collision, not the victim. I put ' if (!PhotonView.isMine) return;' sentence in the OnTriggerEnter method.
    And one more thing that I do not understand.
    I shoot bullets that have values of power(in the script component). But, on other device, you can't read the values. Looks like the bullets cannot carry the values on other devices.

    Is there any good sample codes about multi player shooting game that you recommend?
  • I shoot bullets that have values of power(in the script component). But, on other device, you can't read the values.


    I guess you are instantiating a prefab by using PhotonNetwork.Instantiate(...), don't you? If you modify the any value of an attached script, you have to notify each client about this change. You can do this for example by using a RPC after the object has been instantiated. Or you can do this directly in the PhotonNetwork.Instantiate call using the second overload. Therefore you can use something like this:
    float power = 10.0f; // example
    object[] instantiationData = new object[] { power };
    PhotonNetwork.Instantiate("Object", Vector3.zero, Quaternion.identity, 0, instantiationData);
    This data can be accessed by using the attached PhotonView component. In the following example the Start function is used:
    public void Start()
    {
        PhotonView pView = GetComponent<PhotonView>();
    
        if (pView.instantiationData != null)
        {
            float power = (float)pView.instantiationData[0];
        }
    }
  • mhhk88
    Options
    Now I understand your code. But my bullets are not PhotonNetwork.Instantiated. I don't want to have many network objects.In my game, 20 fighters(maximum) keep shooting automatically. I guess too many network objects make the game slower. Am I wrong?
    If so, is there a way to try your method with normal objects?
  • M4TT
    Options
    I think that PunRPC is the most appropriate way to spawn bullet over the network
    [PunRPC]
    private void Fire(){
    GameObject newShoot = Instantiate(prefab, transform.position, transform.rotation) as GameObject;
    newShoot.velocity = transformDirection(Vector3.forward * somevalue);
    }