Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Box Collider2D size not syncing across the network

Discussion in 'Multiplayer' started by TheDreamEXE, Nov 2, 2016.

  1. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
    Hello all, so I have a simple script that has a hitbox spawn across the network with some changes to the x and y values with some code. Oddly enough, it isn't being sent to the client. The host gets it fine, and the rest of my networking code seems to work perfectly fine. Here's a short snippet:

    Code (CSharp):
    1.  
    2. [Command]
    3. public void CmdSword()
    4. {
    5.  
    6.         hitBox = Instantiate (Resources.Load ("Prefabs/HitBox"), new Vector3 (0.0f, 3.0f, 0.0f), Quaternion.identity) as GameObject;
    7.         hitBox.transform.parent = GameObject.Find(playerName).transform;
    8.  
    9.         hitBoxScript = hitBox.GetComponent<HitBox>();
    10.        
    11.         hitBoxTransform = hitBox.transform;
    12.         hitBoxTransform.rotation = gameObject.transform.rotation;
    13.         hitBoxCollider = hitBox.GetComponent<BoxCollider2D>();
    14.         hitBoxTransform.localPosition = new Vector2 (44f, 0.0f);
    15.         hitBoxCollider.size = new Vector2 (40f, 60f);
    16.  
    17.         NetworkServer.Spawn(hitBox);
    18.         }
    19.  
    any ideas as to what's going on? The hitbox starts as a simple 10x10 square, and I'm just trying to get it to be 40x60 via code.
     
  2. TheDreamEXE

    TheDreamEXE

    Joined:
    May 14, 2015
    Posts:
    60
    So to my understanding, the issue is mainly because the code is coming from a command, and is sent to the server. However, even after toying with a simple RPC that just relays the information back, I am still not getting the desired result. I'm spawning an infinite amount of hitboxes!