title: Unity2D - moving 2D object in a grid like, timed fashion
body: <p>I have been trying to make this work for a while and I am failing. </p>
  
  <p>I have a Rigidbody2D in a top down 2D level and I am trying to simply move it along the coordinates (the levels are gridlike) so one step / button press equals exactly one square walked. It should only be possible to walk in one of the four directions, and no matter when the user stops the walking motion, it should end on a square. A good game equivalent of what I want to achieve is the lufia / breath of fire / any similar RPG series. I've tried using coroutines to get the update function to wait one second after every step, but that does not seem to work. The closest I've come to is the code down below. Thanks guys!</p>
  
  <pre><code>public class PlayerMovement2D : MonoBehaviour
  {    
  Rigidbody2D rbody;
  Animator anim;    
  float speed = 1.25f;
  Vector2 pos;
  void Start()
  {
      rbody = GetComponent&lt;Rigidbody2D&gt;();
      anim = GetComponent&lt;Animator&gt;();
      pos = rbody.position;
  }
  void FixedUpdate()
  {
      Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
      if (movement_vector.x != 0 || movement_vector.y != 0)
      {
          if (movement_vector.x &gt; 0)
          {
              pos += Vector2.right;
              pos.y = 0;
          }          
          else if (movement_vector.x &lt; 0)
          {
              pos += Vector2.left;
              pos.y = 0;
          }
          else if (movement_vector.y &gt; 0)
          {
              pos += Vector2.up;
              pos.x = 0;
          }
          else if (movement_vector.y &lt; 0)
          {
              pos += Vector2.down;
              pos.x = 0;
          }
          anim.SetBool("IsWalking", true);
          anim.SetFloat("Input_x", movement_vector.x);
          anim.SetFloat("Input_y", movement_vector.y);
      }
      else
      {
          anim.SetBool("IsWalking", false);
      }
      rbody.position = Vector2.MoveTowards(rbody.position, pos, speed * Time.deltaTime);
      //transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
      pos = rbody.position;
      }
  }
  </code></pre>