I am trying to write a input script for a twin-stick shooter that takes input from a gamepad on PC or Mac. When I rotate the thumb-stick 360 degrees the input returned rotates smoothly except at the axes (and sometimes the diagonals) where it snaps to the axes or diagnals.
I've attached a minimal [project][1] that exhibits the problem. Rotate the left thumb-stick slowly and you'll see the input vector snap to the axes. This is the relavant code:
public class ThumbStick : MonoBehaviour
{
Vector3 thumbStick;
void Update ()
{
thumbStick = new Vector3(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"), 0);
//thumbStick = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
}
void OnDrawGizmos ()
{
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, 1f);
Gizmos.color = Color.red;
Gizmos.DrawRay (transform.position, thumbStick.normalized);
Gizmos.color = Color.green;
Gizmos.DrawRay(transform.position, thumbStick);
}
}
I've tried:
- Using both Input.GetAxis and Input.GetAxisRaw
- Adjusting the Sensitivity and Type settings of the Horizontal and Vertical axes in the InputManager
- A Logitech Gamepad F310 on PC and Mac
- A PS3 controller on Mac
Is this something inherent in gamepad input that needs to be programmed around, or is Unity adjusting the data somehow (I could see how the snapping would be useful in other games)?
[1]: /storage/temp/9798-smooththumbstick.zip
↧