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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Twin stick style aiming action with gamepad joystick and mouse bindings

Discussion in 'Input System' started by ElnuDev, Feb 22, 2020.

  1. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Is it possible to create a single twin stick style aiming action gamepad joystick and mouse bindings? I'd like to get a
    Vector2
    value in the aiming direction, but I'm not sure how to approach this. Should I have separate actions for joystick and mouse aiming instead? Thanks in advance! :)
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    ATM this does indeed require either separate actions or awkward if() handling in callbacks.

    I'd recommend splitting this into one action meant to deliver screen-space 2D positions and one action delivering normalized direction vectors.
     
    ElnuDev likes this.
  3. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Okay! That's what I ended up doing. Will there be a more elegant way to deal with this kind of thing in future versions of the Input System? Thanks for the help!
     
  4. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    It's on the list (ISX-344). It'll likely be a processor to apply to screen position bindings and some API to set the reference point to use. It's possible to implement such a thing manually today. For example something like:

    Code (CSharp):
    1.     #if UNITY_EDITOR
    2.     [InitializeOnLoad]
    3.     #endif
    4.     public class MouseDirectionProcessor : InputProcessor<Vector2>
    5.     {
    6.         public static Vector2 relativeToScreenPosition;
    7.  
    8.         static MouseDirectionProcessor()
    9.         {
    10.             InputSystem.RegisterProcessor<MouseDirectionProcessor>();
    11.         }
    12.         [RuntimeInitializeOnLoadMethod]
    13.         private static void Initialize()
    14.         {
    15.         }
    16.         public override Vector2 Process(Vector2 value, InputControl control)
    17.         {
    18.             return (value - s_RelativeToScrenPosition).normalized;
    19.         }
    20.     }