I have InputActions that are pretty much the defaults. Specifically, a Look action that uses the pointer delta (action type Value, control type Vector 2).

How can I translate this information into a look angle that I can apply to a gameObject's rotation? I know the traditional way of making an object rotate to look at the mouse is using LookAt and functions like that, but I don't want to use that because (a) I want the looking to be independent of the mouse's distance from the game object and (b) I want to use the Look action since it'll allow the exact same code to be used regardless of whether the player is using a mouse or a joystick on a gamepad (I think).

For example, if I move my mouse in a north-east direction, how can I pull that angle ('north east', i.e. 45 degrees if 0 degrees is north) from the delta values I'm getting?

  • \$\begingroup\$ Usually you'd use different logic for a mouse pointer than a joystick. For a joystick, what matters is where the stick is pushed within its dome of travel. For a mouse, what matters is where the mouse cursor is on-screen relative to the character. I don't think delta values you get natively from the input system are going to be sufficient for your needs, unless you want a cursor below your character to make them look up if it moves up 2 pixels, while staying below the character on screen. \$\endgroup\$
    – DMGregory
    Mar 5, 2023 at 21:13
  • \$\begingroup\$ I'm mostly trying to make a character rotation controller that's independent of mouse distance from the character, is the goal. \$\endgroup\$ Mar 5, 2023 at 21:25
  • \$\begingroup\$ Sounds to me like you just need good ol' atan2. Can you show how you've tried using existing answers about turning a mouse offset into a facing direction to solve this problem, and where you've run into a new issue we can help you with? \$\endgroup\$
    – DMGregory
    Mar 5, 2023 at 21:56


You must log in to answer this question.

Browse other questions tagged .