0
\$\begingroup\$

I'm working on a game in Unity, and it is a little jarring to use with keyboard controls. I'm using the built in Input Manager, where I have a set of axes mapped to the left and right keys. When the player is using the keyboard instead of a joystick, I'd like it to simply be -1 when hitting left, 1 when hitting right, and 0 otherwise, but this isn't the case. I've found that for the first few frames of the button being held, Unity automatically builds up to the value-- for example, if I'm holding right, the value wouldn't go straight from 0 to 1, but rather from 0, to 0.25, to 0.5 and so on, continuously up to 1. Can I deactivate this? If so, how? Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ Presumably you've already configured the gravity, sensitivity, and snap parameters in the Input Manager? Can you show us the values you're using? \$\endgroup\$ – DMGregory Jul 21 '17 at 3:44
3
\$\begingroup\$

You can use the built-in method Input.GetAxisRaw

From the docs:

Returns the value of the virtual axis identified by axisName with no smoothing filtering applied.

The value will be in the range -1...1 for keyboard and joystick input. Since input is not smoothed, keyboard input will always be either -1, 0 or 1. This is useful if you want to do all smoothing of keyboard input processing yourself.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.