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\$
1
  • \$\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, 2017 at 3:44

1 Answer 1

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .