Search Unity

2d top down player movement

Discussion in 'Scripting' started by mmomaker, Jan 31, 2015.

  1. mmomaker

    mmomaker

    Joined:
    Mar 12, 2013
    Posts:
    15
    hi guy um a bit a go i posted a tread about a 2d topdown movement script i mead and it dint work so i went and mead this

    public class playermovement : MonoBehaviour {

    public float speed;

    void Update () {

    if (Input.GetKey (KeyCode.D)) {
    transform.Translate (Vector2.right * speed);

    }
    if (Input.GetKey (KeyCode.A)) {
    transform.Translate (-Vector2.right * speed);

    }
    if (Input.GetKey (KeyCode.W)) {
    transform.Translate (Vector2.up * speed);

    }
    if (Input.GetKey (KeyCode.S)) {
    transform.Translate (-Vector2.up * speed);

    }


    }
    }


    and this allow me to play the game with out a error but the player just dusent move wut so ever
    i have made 2 scrips now for player movemint and both dont work
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Did you give speed a value in the editor?
     
    Kiwasi likes this.
  3. mmomaker

    mmomaker

    Joined:
    Mar 12, 2013
    Posts:
    15
    yes i did im get rilly rilly mad that i cant get a top down player movement script to work for my socil mmo project