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 [9798-smooththumbstick.zip|9798] 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)?
I have exactly the same problem with a xbox 360 pad, using almost the same code with a "deadzone" : shootDirection = new Vector2(Input.GetAxis("HorizontalAim"), -Input.GetAxis("VerticalAim")); if (shootDirection.magnitude < shootData.shootDirectionDeadZone) { shootDirection = Vector2.zero; } shootDirection.Normalize(); I remember I didn't have this issue on XNA (I migrated my project from XNA to Unity 3D). If someone have an idea, I could help a lot!
– AldwinMaybe if you try to make the move with a vector3.Lerp between the current position and the one you want to reach.
– mohaIn this case, it's not about moving from an angle pto another but go directly to the angle given by the stick. And it's this angle returned by the stick which seems "snapped" around the 45° directions...
– Aldwin