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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Unity Netcode] How do I temporarily disable interpolation when being teleported?

Discussion in 'NetCode for ECS' started by khalid_mightybear, Feb 21, 2020.

  1. khalid_mightybear

    khalid_mightybear

    Joined:
    Sep 10, 2017
    Posts:
    36
    How do I temporarily disable interpolation when being teleported?
    Currently I can see my game characters being interpolated to their new teleport point
     
    Mikael-H likes this.
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    There is currently not automatic way of disabling interpolation temporarily, right now you would have to write a custom GhostSnapshotValue.
    In the ghost snapshot value you can write your own code that is called to interpolate - we do that in DotsSample, see https://github.com/Unity-Technologi....Sample.Game/GameBootstrap/GhostAngleValue.cs and https://github.com/Unity-Technologi...cripts/Networking/GhostSnapshotValueAngle.txt .
    You could do some kind of heuristic in the interpolate method, if (distance <= 10) lerp(). If you need to flag it manually you could include some kind of teleportVersion in the snapshot data which you increase every time you teleport so you can do something like if (teleportVerion == target.teleportVerion) lerp().
     
  3. KaneKennste

    KaneKennste

    Joined:
    Oct 1, 2019
    Posts:
    7
    Kind of old, but in case anyone else is wondering how to achieve this: NetworkTransform offers now a function called Teleport. That can be called by the owner.
     
    Opeth001 likes this.
  4. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,078
    do you have a link to it or something? i cant find it in the unity netcode package.
    Thanks
     
  5. KaneKennste

    KaneKennste

    Joined:
    Oct 1, 2019
    Posts:
    7
    I found it by looking into NetworkTransform in Packages/Netcode For GameObjects/Components/NetworkTransform or Library\PackageCache\com.unity.netcode.gameobjects@1.2.0\Components\NetworkTransform. At the bottom you'll find
    Code (CSharp):
    1. public void Teleport(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
    2.         {
    3.             if (!CanCommitToTransform)
    4.             {
    5.                 throw new Exception("Teleporting on non-authoritative side is not allowed!");
    6.             }
    7.  
    8.             // Teleporting now is as simple as setting the internal state and passing the teleport flag
    9.             SetStateInternal(newPosition, newRotation, newScale, true);
    10.         }
    Oh, and one correction to my previous post. it cannot called by the owner. It can be called by the owner if NetworkTransform is Client Authoritative, or by the Server if Server Authoritative.
     
  6. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,078
    It's out of topic, here we are in the DOTS netcode not in the gameobject one.
    But thank you anyway ;)
     
  7. KaneKennste

    KaneKennste

    Joined:
    Oct 1, 2019
    Posts:
    7
    whoops, you're right. my bad :)
     
  8. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    177
    Found this in Netcode changelog:
    * Added a `MaxSmoothingDistance` parameter to the `[GhostField]` attribute. If specified interpolation will be disabled when the values change more than that limit between two snapshots. This is useful for dealing with teleportation and similar changes which should not be interpolated.
     
    Opeth001 likes this.
  9. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,078
    However, it's important to note that this option may not work effectively in all cases. For example, it may not be suitable for fast-moving ghosts that travel at high speeds which start teleporting if they excceed that MaxSmoothingDistance, or for simple short-distance teleportations.