Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Strange behavior with Input System in 2021.3.18

Discussion in 'Editor & General Support' started by Kraythax, Mar 8, 2023.

  1. Kraythax

    Kraythax

    Joined:
    Dec 31, 2022
    Posts:
    17
    I just upgraded my project and now the input system seems to go haywire. I am working on a rigidbody based character controller and I have stripped out most of the controller because things started going nuts. I have WASD configured as axis input and if I hold A I get (-1.0, 0.0) roughly on the input. Holding D inverts that as expected. On the other hand W and S are completely messed up. As I pan the Cinnemachine camera the RAW input seems to shift and skip around unpredictably. Holding W I get (0.334, 0.899) and then changing the follow camera angle it changes to (0.459, 0.777) and slips all over the place. This makes no sense as I haven't changed anything and why should the raw input be affected by the camera direction? This is causing a number of problems in the rest of the controller to the point where its scheme is a scrambled mess. You can imagine the crazy results after trying the standard transform for camera. Is this truly some catastrophic bug and I need to downgrade or did something change that I am not aware of?

    Code (CSharp):
    1.      
    2. /// Get the Raw movement input and transform into a force direction relative to the camera.
    3. private Vector3 GetRelativeMoveInput()
    4. {
    5.     input = moveAction.ReadValue<Vector2>().normalized; // <--- This is completely totally FUBAR
    6.     Debug.Log("1. input = " + input);
    7.     if (input == Vector2.zero) return Vector3.zero;
    8.     Debug.Log("2. forward = " + cameraTransform.forward.normalized);
    9.     Debug.Log("3. right = " + cameraTransform.right.normalized);
    10.     input = cameraTransform.forward.normalized * input.y + cameraTransform.right.normalized * input.x;
    11.     input = input.normalized;
    12.     Debug.Log("4. input = " + input);
    13.     return new Vector3(input.x, 0f, input.y);
    14. }
    15.  
     
  2. Kraythax

    Kraythax

    Joined:
    Dec 31, 2022
    Posts:
    17
    Turns out this was my error. I was trying to use the 3d camera transform to transform the 2d input. The correct action was to project forward and right on the XZ plane and transform there.