Home>

Started writing a 2d game in Unity. I am studying movement through the joystick (for android). All is well, moving left and right. But I can't figure out what needs to be done to make the object move up and down.

Here is my code:

public Joystick joystick;
    private int speed= 4;
    private float moveInput;
    public Rigidbody2D rb;
    public void FixedUpdate ()
    {
        moveInput= joystick.Horizontal;
        rb.velocity= new Vector2 (moveInput * speed, 0);
    }

UPD: Thanks to the answer, I'll make the edit. Here's what I added:

private float moveInput1;
        moveInput1= joystick.Vertical;
        rb.velocity= new Vector2 (moveInput * speed, moveInput1 * speed);
  • Answer # 1

    Mmm ...
    To interrogatejoystick.Vertical;and to set the second component of speed?

  • Answer # 2

    Mmm ...
    To interrogatejoystick.Vertical;and to set the second component of speed?