Skip to content

Commit

Permalink
Removing the network transform child seems to help sync rocks and roc…
Browse files Browse the repository at this point in the history
…kets when connecting multiple clients, the syncvars are all that is needed as I don't update the positions of the child after start.
  • Loading branch information
plaidpants committed Feb 3, 2022
1 parent 3ff87c0 commit 1cb5a4a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
14 changes: 9 additions & 5 deletions Assets/RockField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ public class RockField : NetworkBehaviour
public GameObject RockSpherePrefab;

// Use this for initialization
[Server]
void Start ()
public override void OnStartServer()
{
//if (!isServer) return;
base.OnStartServer();

for (int i = 0; i < numberOfRocks; i++)
{
Expand All @@ -29,8 +28,13 @@ void Start ()
}
}

// Update is called once per frame
void Update ()
public override void OnStartClient()
{
base.OnStartClient();
}

// Update is called once per frame
void Update ()
{
}
}
13 changes: 6 additions & 7 deletions Assets/RockSphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ public class RockSphere : NetworkBehaviour
public GameObject rockSpherePrefab;
public int pieces;
//public float rotationSpeed;
[SyncVar] bool destroyed = false;
[SyncVar] float radius = 0;
[SyncVar] Vector3 pos = Vector3.zero;
[SyncVar] Quaternion rot = Quaternion.identity;
[SyncVar] public bool destroyed = false;
[SyncVar] public float radius = 0;
[SyncVar] public Vector3 pos = Vector3.zero;
[SyncVar] public Quaternion rot = Quaternion.identity;
public static int count = 0;

// Use this for initialization
// [Server]
public override void OnStartServer()
{
// call the base function, probably is empty
Expand All @@ -41,8 +40,8 @@ public override void OnStartServer()

// move the child rock to original location and rotation
rock = transform.Find("Rock.old").gameObject;
rock.transform.position = pos;
rock.transform.rotation = rot;
rock.transform.localPosition = pos;
rock.transform.localRotation = rot;

// apply some rotational torque to the parent gameobject object with the rock attached as a child
Rigidbody rb = GetComponent<Rigidbody>();
Expand Down
Binary file modified Assets/RockSphere1.prefab
Binary file not shown.
Binary file modified Assets/RockSphere2.prefab
Binary file not shown.
Binary file modified Assets/RockSphere3.prefab
Binary file not shown.
Binary file modified Assets/RocketSphere.prefab
Binary file not shown.

0 comments on commit 1cb5a4a

Please sign in to comment.