---
tags:
    - "Analog"
    - "Joystick"
    - "DPad"
    - "Length"
    - "Amount"
    - "Tilt"
---

# Gamepad Stick Magnitude

[Input](index.md) / **Gamepad Stick Magnitude**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

Returns how far the specified Gamepad stick is deflected

## Parameters

| Name | Description |
| :--- | :---------- |
| Stick | Which stick of the current Gamepad is read |

## Code

```cs
using System;
using UnityEngine;
using UnityEngine.InputSystem;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Inline(nameof(m_Stick))]

    [Title("Gamepad Stick Magnitude")]
    [Category("Input/Gamepad Stick Magnitude")]

    [Description("Returns how far the specified Gamepad stick is deflected")]
    [Image(typeof(IconJoystick), ColorTheme.Type.Blue, typeof(BadgeSpeed))]

    [Parameter("Stick", "Which stick of the current Gamepad is read")]

    [Keywords("Analog", "Joystick", "DPad", "Length", "Amount", "Tilt")]

    [Serializable]
    public class TypeNumberInputGamepadStickMagnitude : TypeNumber
    {
        [SerializeField] private GamepadStick m_Stick = GamepadStick.Left;

        public override double Get(Args args)
        {
            Gamepad gamepad = Gamepad.current;
            if (gamepad == null) return 0d;

            Vector2 value = this.m_Stick switch
            {
                GamepadStick.Left => gamepad.leftStick.ReadValue(),
                GamepadStick.Right => gamepad.rightStick.ReadValue(),
                GamepadStick.DirectionalPad => gamepad.dpad.ReadValue(),
                _ => throw new ArgumentOutOfRangeException()
            };

            return value.magnitude;
        }

        public override string ToString()
        {
            return $"Gamepad {this.m_Stick} Magnitude";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}

```

