Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

When pressing Shift... why is not working?

Discussion in 'Input System' started by Javier-Cabrera, Feb 12, 2021.

  1. Javier-Cabrera

    Javier-Cabrera

    Joined:
    Sep 30, 2013
    Posts:
    15
    Hello Unity community,

    I'm trying to Strafe while pressing down shift with the new Input System.

    I have my Inputs working.


    upload_2021-2-12_19-39-7.png

    But when I hold Shift, the movement doesn't work.

    I am using if triggered and the Debug tells me the Shift gets pressed, but the movement is not happening.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class Player : MonoBehaviour
    7. {
    8.     public InputMaster controls;
    9.     Vector2 move;
    10.    
    11.  
    12.  
    13.     void Awake()
    14.     {
    15.         controls = new InputMaster();
    16.  
    17.         controls.Player.Move.performed += ctx => move = ctx.ReadValue<Vector2>();
    18.         controls.Player.Move.canceled += ctx => move = Vector2.zero;
    19.  
    20.        
    21.     }
    22.  
    23.    
    24.  
    25.     void FixedUpdate()
    26.     {
    27.         Vector3 Move = new Vector3(0.0f, 0.0f, move.y) * Time.deltaTime;
    28.         Vector3 Strafe = new Vector3(move.x, 0.0f, 0.0f) * Time.deltaTime;
    29.  
    30.         transform.Translate(Move, Space.World);
    31.  
    32.  
    33.         if (controls.Player.Strafe.triggered)
    34.         {
    35.  
    36.  
    37.             transform.Translate(Strafe, Space.World);
    38.             Debug.Log("Straffing");
    39.         }
    40.  
    41.  
    42.  
    43.  
    44.  
    45.         //transform.Rotate(Vector3.up, 1f * Time.deltaTime);
    46.     }
    47.  
    48.     void OnEnable()
    49.     {
    50.         controls.Player.Enable();
    51.     }
    52.  
    53.     void OnDisable()
    54.     {
    55.         controls.Player.Disable();
    56.     }
    57.  
    58.  
    59. }
     
  2. adanawtn

    adanawtn

    Joined:
    Dec 6, 2020
    Posts:
    3
    I was trying to do the same thing for a dash, but it wasn't working for me either. The input action seemed to be registering, but it wasn't executing the code.
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    10,053
    If you're using shift as a modifier, check out the InputSystem documentation, look for something like composite actions with one modifier. It works differently when you use shift as a standalone key or when you intend to use it as a modifier for an action.