OnCollisionEnter not working with networked objects

Options

Hi,

I have a game where 2 players operate a ball each. I want to detect collisions between the balls, and I tried using the following code:


private void OnCollisionEnter(Collision collision)
  {
    // Return if not ours
    if (!photonView.IsMine) return;

    if (collision.collider.tag == "ball")
    {
      print("collided with ball");
    }

    if (collision.collider.tag == "wall")
    {
      ballTouchWall= true;
    }
    else
    {
      ballTouchWall= false;
    }
  }

Collisions with the walls works perfectly as expected. I tried writing a print at the top of the function with collisions.collider.tag and it never prints "ball" though.

My balls are spawned in and are in the scene/hierarchy. Both balls have a rigidbody and spherecolliders. Colliders doens't have isTrigger. Collision detection is set to continous dynamic.

What is wrong, why isn't the oncollisionenter working between balls?

Answers

  • Z060049
    Options

    I have the same problem. My guess is that tag system doesn't work with Photon. Not sure what to do

  • Tobias
    Options

    PUN 2 does not use the tag system, so .. by all means, I would expect it to just work. Maybe it does not work for instantiated prefabs? Provided you made sure the prefab has tags?

    Also, your OnCollisionEnter does not do anything in case the object with the callback is not yours. What happens if you don't check IsMine this way?