#Teleportation not working

1 messages · Page 1 of 1 (latest)

static sparrow
#

Hello,

Unity: 6.2
Netcode for GameObject: 2.6.0 (tested also with 2.5.1)

I'm trying to teleport my players (Host/Client) to a specified position. But whatever I do it's not working.

I'm using a NetworkTransform on my players object to sync positions, with the Authority Mode set to Owner. (also tried as Server)

I have a script attached and trying to teleport the player to a new position. But whatever I do, the player moves to new position for a frame then comes back to the same position.
I tried to just simply do:

if (IsOwner)
{
  - transform.position = XXX
  - GetComponent<NetworkTransform>().Teleport(XXX)
  - GetComponent<NetworkTransform>().SetState(XXX)
}

None of this system is working, it's always keep doing the same effect.

Disabling Interpolation doesn't change anything.

Unchecking Position Sync before playing on the Prefab is fixing the issue, but I need it so...

Am I doing something wrong ? Is there any way to do teleportation in a simple way ? (This problem happens with or without connected clients).

In the video, i'm trying to teleport, as you can see, the camera is slightly moving, it's due to the player moving, and sometimes we can even see the player at the new position before it go back to initial position)

lament quest
#

When are you calling this function? Post he entire script. You should also be able to teleport the regular transform as well. It sounds like it's not the actual owner running that code.

static sparrow
# lament quest When are you calling this function? Post he entire script. You should also be ab...
[RequireComponent(typeof(Character))]
[RequireComponent(typeof(SpellCaster))]
public class CharacterInput : NetworkBehaviour
{
    ...

    public override void OnNetworkSpawn()
    {
        if (!IsOwner)
        {
            enabled = false;
        }
        else
        {
            GetComponent<PlayerInput>().enabled = true;
        }
    }

    public void OnMove(InputAction.CallbackContext context)
    {

        ...
    }
    public void OnJump(InputAction.CallbackContext context)
    {
        ...
    }

    public void OnCrouch(InputAction.CallbackContext context)
    {
        ...
    }

    public void OnInteract(InputAction.CallbackContext context)
    {
        ...
    }

    public void OnTeleport(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            if (IsOwner)
            {
                Vector3 target = transform.position + new Vector3(1, 0, 1);
                GetComponent<NetworkTransform>().SetState(target);
            }

        }
    }
  ...

}

So this is my code, I cleaned a little the useless part to make it more clear

This is attached to my player object. And is called directly with the Input manager. I put the code directly here for testing purpose to be faster to debug

And is properly enabled only if it's the owner.

lament quest
#

Hrm, that should be fine. Is the player a child any other object?

static sparrow
#

Sometimes it does work, but rarely

#

So in case another script is interacting on the player movement, I disabled all the components attached to the player object. And kept only inputs related one.
Exactly same situation

lament quest
#

Can you try it in a fresh scene? Or on an object that is not the player?

static sparrow