EDIT: If your controller axes “snap” to 8-directional rotations, make sure the axis sensitivity is set to a “mild” value like 1 and/or that you’re using radial deadzones . Those two seem to be the main issues that make the problem rise. The reply might be useful if your joystick controls make use of the magnitude (how far from the center of the stick you move)
I’m making a 2.5d space shooter, and rather than having a “twin stick” movement I have a “thrust” button and a “turn” thumbstick: wherever you point, the ship turns that way.
I also have mouse-kb input which works well.
I have a “controller snapping” problem on my hands, where the horizontal/vertical axes only have extreme values (either -1 or 1) when the thumbstick is on the edge of its “circle”.
I’ve tried with three pads so far: a generic Logitech, a (severely worn) 360 and a Steam Controller.
I don’t know if this is what exactly is happening, but my best guess is that the axes only have the intermediate values inside a square:
Now, this is an extreme representation, but on the edge of the circle it seems very easy to be on the (1,1), (-1,1), etc. inputs compared to… anything else, really. BUT when the stick is approximately inside the square then I can rotate freely.
Just to be sure it’s not a hardware/driver problem, I tried playing Beat Hazard Demo and I was able to move around as I pleased, as close to the edge as I wished.
The “Horizontal” and “Vertical” input axes that I’m using pretty much have the default parameters, and I’m using a radial deadzone, a clamping to the input magnitude and a “square to circle” transformation.
Keep in mind that this snapping problem is present with or without those things.
Is there something I don’t understand about how the input axes work?
These are the hor/ver axes:
This is the relevant code, although I believe it has to do with the axis input itself, but might as well show it:
//JOYSTICK INPUT
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
//Transform square axes into circle
float horin = h * Mathf.Sqrt(1 - 0.5f * h * h);
float verin = v * Mathf.Sqrt(1 - 0.5f * v * v);
joyin = (new Vector3(horin, 0.0f, verin));
//Joystick deadzone and clamping
if (Mathf.Abs(joyin.magnitude) <= JoystickDeadzone)
joyin = Vector3.zero;
else
joyin = Vector3.ClampMagnitude(joyin, JoystickClamp);
//MOUSE INPUT
...
bool UsingJoystick = (joyin != Vector3.zero);
bool UsingMouse = ...
//Mouse input: project mouse position onto game plane
if (UsingMouse)
{
...
}
//Joystick input: depending on joystick output, turn around
if (UsingJoystick)
{
float r = 256.0f;
directioninput = r * joyin;
targetpos = transform.position + directioninput;
}
//Boost input
...
//Thrust input
...
//Actually move the ship
#region
Vector3 goalpos = transform.position + directioninput;
engine.MoveThing(goalpos, thrustinput, boostinput, true);
For reference, engine.MoveThing() simply thrusts and turns the ship towards the desired position.