- Home /
How to make a joystick axis input equivalent to keyboard input.
Hi everybody. :) I am making a 2D platformer and I am trying to settle an issue with input. My character moves significantly faster when being moved using a joystick than the keyboard. As you can imagine, this is not acceptable for a game where you need to make a precision landing or a skillful long jump, since the conditions for precision are more difficult and speed is incraesed on the joystick. I don't want to play a guessing game with the sensitivity scale. Is there a solution for this, please? Sorry for my ignorance, I am quite new to working with Unity. O:)
In Unity's Input menu, when used to simulate an axis input, keyboard keys can have sensitivities, gravities, and specific extents. Ensure these settings are similar for your keyboard axis and its joystick counterpart. That might account for a discrepancy. Otherwise yeah, gotta see code.
Thanks, guys. I just made a mistake with the sensitivity setting.
Answer by bubzy · Oct 26, 2014 at 01:36 PM
you could just make the joystick input "digital" instead of "analog"
something like
using UnityEngine; using System.Collections;
public class joystickControl : MonoBehaviour {
// Use this for initialization
bool movingLeft = false;
bool movingRight = false;
public float moveSpeed = 1f;
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetAxis("Horizontal") == 0)
{
movingRight = false;
movingLeft = false;
}
if(Input.GetAxis("Horizontal") > 0 )
{
movingRight = true;
movingLeft = false;
}
if(Input.GetAxis("Horizontal")< 0 )
{
movingLeft = true;
movingRight = false;
}
if(movingLeft)
{
transform.position = new Vector3(transform.position.x - (moveSpeed * Time.deltaTime), transform.position.y,transform.position.z);
}
if(movingRight)
{
transform.position = new Vector3(transform.position.x + (moveSpeed * Time.deltaTime), transform.position.y,transform.position.z);
}
}
}
ALSO!!!
under input settings (edit>project settings>input), check the "horizontal" axes, and change the gravity on them to 10000 or something. note that there are two horizontal axes one for joystick and one for keyboard.
hope this helps.
This helped, thanks. I used the gravity setting and things seem to be moving much nicer now. And thanks for the code example.