Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

How do set the initial position of a rigidbody with a network transform.

Discussion in 'Multiplayer' started by spirail, Feb 17, 2023.

  1. spirail

    spirail

    Joined:
    Oct 16, 2017
    Posts:
    1
    I have a button that spawns in a gameobject with a Network Rigidbody and a Network transform.

    The game object prefab is at (0,0,0). But If I want to set an initial position to (-3,0,0), what I see on the client is an object spawning at (0,0,0) then quickly sliding into place at (-3,0,0).

    Even if I look carefully on the server instance, I see a brief flash where the object is at (0,0,0).

    What am I missing here?

    Code (CSharp):
    1.  
    2.  
    3. public class RobotControl : NetworkBehaviour
    4. {
    5.     new private Rigidbody rigidbody;
    6.  
    7.     public Vector3 defaultPosition = new Vector3(-3, 0, 0);
    8.  
    9.     public override void OnNetworkSpawn()
    10.     {
    11.         if (NetworkManager.Singleton.IsServer){
    12.             rigidbody = GetComponent<Rigidbody>();
    13.             rigidbody.position = defaultPosition;
    14.         }
    15.     }
    16. }
    17.  
    I'm running netcode 1.2.0