playMaker

Author Topic: 2D set rotation on Z axis from mouse input vector  (Read 783 times)

10high

  • Playmaker Newbie
  • *
  • Posts: 33
    • Cult Manager - Google Play
2D set rotation on Z axis from mouse input vector
« on: October 04, 2021, 03:27:48 PM »
Hi - I'm making a 2D top-down shooter.

Ideally, I would like to lock and hide the mouse cursor and set the player's Z rotation based on the direction they move the mouse.

For example, they move the mouse up, the player looks up. If they move the mouse to the right, the player rotates in that direction.

I have been sweating this problem for a couple of days now. I have found a couple of Unity solutions from questions asked by others, but I can't seem to get anything to work. For example, https://answers.unity.com/questions/1824600/set-2d-player-rotation-on-z-to-virtual-joystick-ve.html which suggests:

Code: [Select]
transform.rotation = Quaternion.LookRotation(DirectionVector)
In my mind, it would be similar to moving a joystick to control the direction the player looks in.

Is what I'm trying to do possible?
Any suggestions on how to approach this would be appreciated. Thanks.
Cult Manager