07-10-2024, 04:38 PM
I need to spawn objects in runtime, so everything needs to be a prefab. When creating a scene, I instantiate obi rope and spawn 2 plugs, that I can pick up, I connect them to the rope and that is it. On host: Everything works fine, on client: rope gets disconnected from plug and starts to do some weird movement. That only happens when everything is instantiated in runtime.
SimulationBehaviour code:
Code:
bool first = true;
public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
{
if (runner.IsSceneAuthority)
{
if (first)
{
runner.Spawn(prefab, new Vector3(1, 0.089f, 0));
runner.Spawn(prefab, new Vector3(-1, 0.089f, 0));
first = false;
}
runner.SetPlayerObject(player, runner.Spawn(playerPrefab, new Vector3(UnityEngine.Random.Range(-10, 10), 1, UnityEngine.Random.Range(-10, 10)), inputAuthority: player));
}
}
plug code (there is more code, but for this question, this is the important part. Parent is in main project something else, this is just for testing):
Code:
Transform parent;
Rigidbody rb;
private void Start()
{
parent = transform;
rb = parent.GetComponent<Rigidbody>();
if (a.Att1.target == null)
{
a.Att1.target = transform;
}
else
{
a.Att2.target = transform;
}
}
public void Pickup(Transform hand)
{
rb.isKinematic = true;
rb.useGravity = false;
parent.SetParent(hand);
parent.localPosition = Vector3.forward;
}
public void Release()
{
rb.isKinematic = false;
rb.useGravity = true;
parent.SetParent(null);
}
I also set the Time.timeScale = 0 at start of creating the scene, and at the end back to 1.
Here is a video for better understanding of the problem: [color=var(--theme-link-color-hover, var(--theme-secondary-500))]https://drive.google.com/file/d/1P0H2jcFyjb4VeKeQxLUOMf9-ppuZqm9X/view?usp=sharing[/color]