XBOX controller DPAD

The DPAD’s range is from (-1 to 1), but I was wanting to use it as 4 buttons. I am not certain if this is the best solution, but I call CrouchToggle() (for example) from my ProcessDirectMovement method. CrouchToggleDelay can be adjusted as a SerializedField. This is creating a delay of a few frames so that the dpad can be detected like a regular button. If there is a better solution, I would love to hear about it.

I’ve programmed the DPAD axis in the Input Manager to only report [-1, 0, 1] to make it a bit easier to manage.

   private void CrouchToggle()
    {
        if (Input.GetAxis("DPAD Vertical") == -1)
        {
            CrouchToggleCount++;
            if (CrouchToggleCount > CrouchToggleDelay)
            {
                m_crouch = !m_crouch;
                CrouchToggleCount = 0;
            }
        }
    }

Does it work? Really that is the most important thing. That it works and that you intuited a solution yourself.

Is there a better method for it? Sometimes there is a better way, sometimes there is just “other” ways. In this case I don’t really see what is wrong with it. In fact you created a sort of dual button use setup already, where if you just tap the d-pad you can activate one function, and then if you up the CrouchToggleDelay up a bit more you have a hold to activate function. Many games use this feature, think tapping the trigger to activate a quick attack, and holding the trigger to do a charged attack.

You would have to have another check of course for this feature to work (check if dpad vertical is 0 and togglecount < delay, so essentially checking when they release the button before it hits the longer delay).

Privacy & Terms