- Home /
Why isn't my joystick code working?
I am fairly new to Unity and I'm using this code for a joystick (2D), it won't do anything and I can't figure out why. Thanks!
 using UnityEngine;
 
 public class Player : MonoBehaviour {
 
     public Joystick joystick;
     public Rigidbody2D rb;
     public float speed = 100f;
 
     private void Update ()
     {
         rb.velocity = new Vector2(joystick.Horizontal * speed, joystick.Vertical * speed);
     }
 
 }
 
               Comment
              
 
               
              Where did you get this "Joystick" class from ?
While joystick buttons can be monitored using Input.Get$$anonymous$$ey($$anonymous$$eycode), for joystick axes, AFAI$$anonymous$$, you need to use the Input class and Input Settings, like Input.GetAxis("Horizontal").
Answer by hexagonius · Oct 27, 2018 at 02:45 PM
Either speed is 0 or joystick.Horizontal and joystick.Vertical are 0. Since you did not past the relevant code that 's the only answer I can give you.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                