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

How to teleport without lerp?

Discussion in 'Multiplayer' started by Comolokko, Mar 30, 2016.

  1. Comolokko

    Comolokko

    Joined:
    Jul 24, 2014
    Posts:
    28
    Hello,
    I tried to teleport player with transform.position but other players sees it with lerp. How can I teleport a player without lerp? I'm using rigidbody2D and syncing rigidbody
     
  2. Freakyuno

    Freakyuno

    Joined:
    Jul 22, 2013
    Posts:
    138
    If you set a new position of an object by setting it's transform or rotation, then no lerping is going to happen. You'll need to post your code to let us look at it and see what the problem might be.
     
  3. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    Your position syncing script can't handle a teleport so its only lerping the position. You need to modify it to teleport the player if the distance is larger than a threshold.
     
  4. Comolokko

    Comolokko

    Joined:
    Jul 24, 2014
    Posts:
    28
    @Freakyuno here is the code

    Code (CSharp):
    1. void FixedUpdate()
    2.     {
    3.         if (!isLocalPlayer)
    4.             return;
    5.         Collider2D col = Physics2D.OverlapCircle(playerCheck.position, circleRadius, whatIsPlayer);
    6.         onPlayer = Physics2D.OverlapCircle(playerCheck.position, circleRadius, whatIsPlayer);
    7.         if (col != null && onPlayer)
    8.         {
    9.             if (isServer)
    10.             {
    11.                 RpcRespawn(col.gameObject);
    12.             }
    13.             else
    14.             {
    15.                 CmdCallRespawn(col.gameObject);
    16.             }            
    17.         }
    18.     }
    19.  
    20. [ClientRpc]
    21.     void RpcRespawn(GameObject go)
    22.     {
    23.         Debug.Log("CLIENT RPC");
    24.         Vector3 spawnPoint = Vector3.zero;
    25.         if (spawnPoints != null && spawnPoints.Length > 0)
    26.         {
    27.             spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position;
    28.         }
    29.         go.transform.position = spawnPoint;
    30.     }
    31.  
    32.     [Command]
    33.     void CmdCallRespawn(GameObject gogo)
    34.     {
    35.         Debug.Log("COMMAND");
    36.         RpcRespawn(gogo);
    37.     }