- Home /
[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? : )
Answer by tanoshimi · Oct 25, 2013 at 06:03 PM
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);
}
It's partially working, the character facing direction isn't changing in the deadzone, but the rotation now seems restricted to 45 degrees, 135 degrees, 225 degrees, 315 degrees. Any ideas?