Thumbstick and Mouse Support for 2D Top-down Freelook?

Hello,

I’m making a 2D top-down prototype to learn the new input system and I implemented the ability for the player sprite to rotate according to the thumbstick or mouse position. For the action map, I came up with this:

5356239--541308--upload_2020-1-10_2-1-1.png

The action returns a Vector2 value. However, I found that I had to do additional processing on the pointer position, namely a screen space transformation to turn it into a usable direction vector:

void Update()
{
    if (_lookInput.action.triggered)
    {
        var dirVector = _lookInput.action.ReadValue<Vector2>();

        if (_lookInput.action.activeControl.parent.name == "Mouse")
        {
            dirVector = _playerCamera.ScreenToWorldPoint(dirVector);
        }

        // Other processing...
    }
}

Is this a proper way to do it or is there a better way? I keep getting a hunch that I’m doing it wrong…

I have the same issue the other way around, the mouse position suits my need but the stick vector2 does not, I have to transform it relative to camera. I used a custom porcessor wich works great if you only have one camera, for multiplayer, I’m stuck (I just posted a new theead on hte topic).

FYI here is a non tested processor for your used :

using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;

#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class ToWorldPoint: InputProcessor<Vector2>
{

#if UNITY_EDITOR
    static ToPointerPosition()
    {
        Initialize();
    }
#endif

    [RuntimeInitializeOnLoadMethod]
    static void Initialize()
    {
        InputSystem.RegisterProcessor<ToPointerPosition>();
    }


    public Camera m_Camera;

    public override Vector2 Process(Vector2 value, InputControl control)
    {   if (m_Camera == null) m_Camera = Camera.main;
       return  m_Camera.ScreenToWorldPoint(dirVector)
    }
}

You just ha.ve to had it to the list of processors in your action map on the mouse pointer