Search Unity

[HELP] 2D character Controller

Discussion in '2D' started by _Evasi0n, Apr 21, 2015.

  1. _Evasi0n

    _Evasi0n

    Joined:
    Apr 13, 2015
    Posts:
    9
    i wanna make a 2d platformer and i need some help with the character controller
     
  2. leprkon56

    leprkon56

    Joined:
    Apr 21, 2015
    Posts:
    2
    I've also been looking for one, I cant seem to find one yet. :/
     
  3. dreyescairo

    dreyescairo

    Joined:
    Dec 21, 2014
    Posts:
    6
    you'll want something like this if you are using rigidbodies

    Code (CSharp):
    1.  
    2. public float moveSpeed;
    3.  
    4. void FixedUpdate(){
    5.  
    6. if(input.getkey(keycode.A){
    7. GetComponent<Rigidbody2D>.velocity = new vector2 (-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
    8. //to flip sprite
    9. transform.localscale = new Vector3(-1,1,1);
    10. }
    11. if(input.getkey(keycode.D){
    12. GetComponent<Rigidbody2D>.velocity = new vector2 (moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
    13. //to flip sprite
    14. transform.localscale = new Vector3(1,1,1);
    15. }
    16.  
    17.  
    18. }

    for jumping you'll want to set a jumpHeight float and change your x velocity according to your jumpHeight.
     
  4. leprkon56

    leprkon56

    Joined:
    Apr 21, 2015
    Posts:
    2
    ty dreyescairo
     
  5. okaneiba

    okaneiba

    Joined:
    Apr 22, 2015
    Posts:
    1
    That still doesnt work for me.. i have tried like 4 scripts, and the *game still wont run.
     
  6. Redden44

    Redden44

    Joined:
    Nov 15, 2014
    Posts:
    159