Search Unity

Making the Camera look at the Cursor?

Discussion in '2D' started by patrikspengler, Jan 13, 2014.

  1. patrikspengler

    patrikspengler

    Joined:
    Jan 13, 2014
    Posts:
    2
    I'm trying to make a top-down game where as you turn with your character using your mouse, your camera turns as well and looks at the mouse. I've tried a lot of things already but the camera either spins around crazily or doesn't turn at all.


    Is there a way in Unity2D to make the Camera look at the Cursor(rotating the Camera on it's z axis)?
    Any help would be really appreciated.
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You need the angle from the center of the screen to the mouse position, and then plug that into the camera's z angle... but work in euler angles. You may need to convert radians to degrees at some point.
     
  3. patrikspengler

    patrikspengler

    Joined:
    Jan 13, 2014
    Posts:
    2
    Could you show that in code? It does not work for me.