1

I'm trying to set up a joystick control, but it's not working.

Below are the buttons I set up in Axis Input:

enter image description here

my code:

 void FixedUpdate()
    {
        bool running = Input.GetKey(KeyCode.LeftShift);

        //float h = Input.GetAxisRaw("Horizontal"); //keyboard
       // float v = Input.GetAxisRaw("Vertical"); //keyboard

        float h = Input.GetAxisRaw("LeftJoystickHorizontal");
        float v = Input.GetAxisRaw("RightJoystickVertical");

        bool isWalking = Mathf.Abs(h) + Mathf.Abs(v) > 0;

        movement = ((running) ? runSpeed : walkSpeed) * new Vector3(h, 0.0f, v).normalized;
        if (isWalking)
        {
            transform.position += movement * Time.fixedDeltaTime;
            transform.LookAt(transform.position + movement);
        }

But it is not working, the player moves only to one place. And I can not let the movements of the joystick with those of the keyboard. What am I doing so wrong?

  • What are you trying to do with `bool isWalking = Mathf.Abs(h) + Mathf.Abs(v) > 0;`? – Ryolu Oct 03 '18 at 01:27
  • why are you grabbing the horizontal movement of the left joystick and the vertical movement of the right joystick to determine whether or not the user is walking? Are you supposed to move left and right with the left joystick and up and down with the right joystick? – Alox Oct 04 '18 at 12:24

0 Answers0