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. Dismiss Notice

Question Short/Long range ghost teleport

Discussion in 'NetCode for ECS' started by Opeth001, Mar 2, 2023.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,068
    Hello,
    I just finished reading the new DOTS netcode documentation and saw a little note about interpolated ghosts and teleportation.
    It seems like the main way to do this is to set a maximum interpolation range so that the netcode will automatically teleport an interpolated ghost if that range is exceeded and for short distance teleports. It indicates that an extra bit can be used.
    Can you explain this approach further?
    THANKS!
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    224
    Hey Opeth,

    EDIT: See Tim's more comprehensive answer below.
     
    Last edited: Mar 2, 2023
    Opeth001 likes this.
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,068
    Thanks @NikiWalker,
    You are as always super reactive !! :)
    I still don't really understand how things work in the netcode package.
    Can you please provide more details on disabling smoothing for interpolated ghosts?
    like how it can be done !
     
  4. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    MaxSmoothingDistance is by far the easiest way to deal with teleporting in most cases, if you do need short distance teleportation and it is important that you do not get an in-between position the extra bit mentioned requires that the component and interpolation function is changes.

    You would need the component to be something like
    Code (CSharp):
    1. struct MyPos
    2. {
    3.     float3 Position;
    4.     byte isTeleport:
    5. }
    and the interpolation method for it would do something like
    Code (CSharp):
    1. if (fieldAfter.isTeleport != 0)
    2.     component.field.Position = fieldBefore.Position;
    3. else
    4.     component.field.Position = math.lerp(fieldBefore.Position, fieldAfter.Position, value);
    This is pseudo code, it will not compile and you might need to iterate on it to get ti working.

    The gameplay code will be responsible for setting isTeleport whenever it does perform a teleport for this to work, and you need custom type templates for the struct
     
    Opeth001 likes this.
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,068
    Thanks!