Search Unity

Basic Teleportation 2d Need Help:)

Discussion in '2D' started by noahnsteiner, Apr 12, 2019.

  1. noahnsteiner

    noahnsteiner

    Joined:
    Mar 27, 2019
    Posts:
    2
    Hi im new to coding and I'm trying to move a game.object on a grid map one grid up if I press w
    But idk how :) pls help me :)
     
  2. zioth

    zioth

    Joined:
    Jan 9, 2019
    Posts:
    111
    You can change a GameObject's position with:

    "obj.transform.position = new Vector2(x, y);"

    So if your grid squares are 1x1, and you want to move the object up one square, you'd do this:


    Vector2 curPos = obj.transform.position;
    curPos.y--;
    obj.transform.position = curPos;
     
  3. noahnsteiner

    noahnsteiner

    Joined:
    Mar 27, 2019
    Posts:
    2
    Thx worked wonders