Teleport Player in 2D game?

Hello, I’m an extreme Unity-beginner, and what I want to do is teleport my 2D character to a specific set of coordinates. However, if I access their transform.position and set it equal to the corresponding Vector 2, my character starts to fly upwards, considering the fact that they have a rigidbody attached. Is there any way for me to teleport my player without this happening?
Update: I have already tried a Vector 3 instead of a Vector2, and I have also tried editing the Rigidbody’s position as opposed to the players. Both of them result in the “floating upwards” effect.

Transform.position is a Vector3.

Change your Vector 2 to a Vector3.

The reason for this is because the 2D engine is just the 3D engine, but you are playing with flat images.

Try using rigidbody.position instead

GetComponent().position = newPosition;

If you want to continuously move a rigidbody use MovePosition instead, which takes interpolation into account.


For more details:

Try this.

  Player.transform.position = new Vector4(x,y,x);

make sure somewhere in your code you have Public GameObject Player;
and that in inspector you told the game that the variable Player is reffering to your Player.

Player can be whatever name you want but Player is nice and easy for this example.

In the vector4, the x y z can be replaced with your desired x and y co-ordinates, as you are doing 2d the z can be set to 0.

Bassically, what this code does is it access
s the position of the player, and replaces its current position with a whole new position that it stored in a new variable, (hence, new vector4)

@unity_O9yFOEld5ESRvw
After assigning the position, try adding

  rigidbody.Sleep();
  rigidbody.velocity = Vector3.zero;