Home > database >  Unity 3D Trying To Disable Joystick Controls So The Character Can't Move While Aiming
Unity 3D Trying To Disable Joystick Controls So The Character Can't Move While Aiming

Time:05-22

I'm trying to disable the joystick controls so when I zoom in on my character(and he is aiming), he won't start to move if the player accidently hits the joystick while he is in aim mode.

Im using the --new input system from the starter assets (action type/passthrough & control type/Vector2)-- and I'm using a locomotion blend tree (2D free form Directional as the blend type)

(The two lines below are what I want to disable)

playerControls.PlayerMovement.Movement.performed = i => movementInput = i.ReadValue();
playerControls.PlayerMovement.Camera.performed = i => cameraInput = i.ReadValue();

private void OnEnable()
{
    if (playerControls == null)
    {
        playerControls = new PlayerControls();

        playerControls.PlayerMovement.Movement.performed  = i => movementInput = i.ReadValue<Vector2>();    
        playerControls.PlayerMovement.Camera.performed  = i => cameraInput = i.ReadValue<Vector2>();

        playerControls.PlayerMovement.Run.performed  = i => runInput = true; /// Hold
        playerControls.PlayerMovement.Run.canceled  = i => runInput = false; /// Let Go

        playerControls.PlayerMovement.QuickTurn.performed  = i => QuickTurnInput = true;

        playerControls.PlayerActions.Aim.performed  = i => aimingInput= true; 
        playerControls.PlayerActions.Aim.canceled  = i => aimingInput = false;

        playerControls.PlayerActions.Shoot.performed  = i => shootInput = true;
        playerControls.PlayerActions.Shoot.canceled  = i => shootInput = false;
    }

    playerControls.Enable();
}

CodePudding user response:

My best bet is for you to disable movement while aim was performed like this:

playerControls.PlayerMovement.Movement.performed  = i => movementInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;
playerControls.PlayerMovement.Camera.performed  = i => cameraInput = i.ReadValue() && playerControler.PlayerActions.Aim.performed;

You can try it, but move this snippet below your Aim.performed snippet

CodePudding user response:

I figured it out for the most part. here is what I used

    if (playerManager.isAiming)
        {
            playerControls.PlayerMovement.Movement.performed  = i => movementInput = Vector2.zero;
        }
        else
        {
            playerControls.PlayerMovement.Movement.performed  = i => movementInput = i.ReadValue<Vector2>();
        }

unfortunately I had a boolean that I forgot to disable so that is what gave me most of my problems.

  • Related