Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How to make keyboard react like controller

Discussion in 'Input System' started by Cosmology27, Apr 24, 2021.

  1. Cosmology27

    Cosmology27

    Joined:
    Jul 11, 2019
    Posts:
    61
    I currently have my fps character moving by regular keyboard inputs on a character controller (wasd) and then input.getaxis horizontal and vertical. I have remapped the left stick on the xbox to use those as well, so movement feels like a normal fps should.
    My problem is that, when I use the controller, the movement feels extremely responsive, quick, precise, but when I use the keyboard wasd, it floats a bit, so if I press W to go forward, and I release it, there's a brief slowdown period (very small, but still).
    Why is it giving that little floaty feeling, and how do I get rid of it?

    Like I said, I'm using a character controller on the player, and then here's my little bit of script for mapping the controller to move too.

    Code (csharp):
    1. float x = Input.GetAxis("Horizontal");
    2. float z = Input.GetAxis("Vertical");
    3. Vector3 move = transform.right * x + transform.forward * z;
    4. controller.Move(move * speed * Time.deltaTime);
     
  2. LittleDirge

    LittleDirge

    Joined:
    Dec 3, 2018
    Posts:
    6
    I think that this is due to the project settings/input manager settings for Horizontal and Vertical and working on a keyboard. Under Edit > Project Settings > Input Manager > Horizontal / Vertical. There are two fields to consider: Sensitivity and Gravity. On a keyboard, you're really only getting on or off for a button press, also known as 1 and 0. The sensitivity represents how quickly the input manager moves from 0 to 1 and the gravity represents how quickly it returns from 1 to 0 (at least with keyboard). The reason you're not getting the same feeling with the controller is because the angle of the stick itself is what is being measured, so letting go of the stick snaps it back to '0' more quickly than the kinda linear change you're getting through the input manager.
     
    Cosmology27 likes this.
  3. Cosmology27

    Cosmology27

    Joined:
    Jul 11, 2019
    Posts:
    61
    Thanks! That perfectly fixed the problem!