[Top down shooter] control pad issue when analogue stick neutral

Hi,

I’ve managed to get an xbox 360 controller working in my game, but whenever I let the analogue stick go, the character faces north. I’d like them to face whatever direction they were facing. Here’s the code I’m using:

// Get direction analogue stick is pointed to
tempVector = new Vector3(Input.GetAxis("RotationX"), 0, Input.GetAxis("RotationY"));

// Set rotation
inputRotation = tempVector;

// Set the object's rotation
transform.rotation = Quaternion.LookRotation(inputRotation);

Have saved the rotation of previous update, and tried comparing them, but I’m a bit braindead today and haven’t been able to get it to work. Can someone lend a hand? : )

Perhaps try wrapping your set rotation script in an if() statement that checks that the stick has been pushed sufficiently far out of “neutral” (also known as deadzone). Something like (untested):

// Get direction analogue stick is pointed to
tempVector = new Vector3(Input.GetAxis("RotationX"), 0, Input.GetAxis("RotationY"));
 
float deadzone = 0.25f;

if(tempVector.sqrMagnitude > deadzone) {
  transform.rotation = Quaternion.LookRotation(tempVector);
}