Question: I want my sprite to move either up or down or left or right, I don't want any other movement such as north-west or south-east; it needs to be either up, down, right or left. There are similar posts like this on the internet but I was wondering why mine wasn't working. It doesn't initiate any movement in the game. 

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public Sprite Up;
    public Sprite Down;
    public Sprite Right;
    public Sprite Left;
    public float speed;

    // Update is called once per frame
    void Update()
    {

        Vector3 move = transform.position;

        if (Input.GetKey(KeyCode.W))
        {
            GetComponent<SpriteRenderer>().sprite = Up;
            move.z += speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.A))
        {
            GetComponent<SpriteRenderer>().sprite = Left;
            move.x -= speed * Time.deltaTime; 
        }
        if (Input.GetKey(KeyCode.D))
        {
            GetComponent<SpriteRenderer>().sprite = Right;
            move.x += speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.S))
        {
            GetComponent<SpriteRenderer>().sprite = Down;
            move.y -= speed * Time.deltaTime;
        }

      transform.position = move; 
    }
}

```

For what I am looking for, I don't think I need rigidBody as most people include in their movement. I'm still a beginner so an in-depth explanation of why my code isn't working and what I could do to fix it would be helpful. Thanks.

Answer: 
First, you should cache your SpriteRenderer, here you're doing up to 4 GetComponent calls just for movement.

Then, you don't want to directly set the position of your object, but move it. You can either do transform.Translate(move), or transform.position += move;

edit : and you should probably assign the sprite basing on the final movement. Here you will override it every time as your ifs are not exclusive
Solution : 

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public Sprite Up;
    public Sprite Down;
    public Sprite Right;
    public Sprite Left;
    public float speed;

    // Update is called once per frame
    void Update()
    {

        Vector3 move;

        if (Input.GetKey(KeyCode.W))
        {
            GetComponent<SpriteRenderer>().sprite = Up;
            move = new Vector2(0, speed * Time.deltaTime);

            transform.position += move;
        }
        if (Input.GetKey(KeyCode.A))
        {
            GetComponent<SpriteRenderer>().sprite = Left;
            move = new Vector2(speed * Time.deltaTime, 0);

            transform.position -= move;
        }
        if (Input.GetKey(KeyCode.D))
        {
            GetComponent<SpriteRenderer>().sprite = Right;
            move = new Vector2(speed * Time.deltaTime, 0);

            transform.position += move;
        }
        if (Input.GetKey(KeyCode.S))
        {
            GetComponent<SpriteRenderer>().sprite = Down;
            move = new Vector2(0,speed * Time.deltaTime);

            transform.position -= move;
        }

    }
}

```