# Rotation using Unity2D

**URL:** <https://discussions.unity.com/t/rotation-using-unity2d/92670>\
**Category:** Questions & Answers\
**Created:** [January 14, 2014, 9:05am UTC](https://discussions.unity.com/t/rotation-using-unity2d/92670 "2014-01-14T09:05:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BillyM148](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@BillyM148](https://discussions.unity.com/u/BillyM148)\
**Post date:** [January 14, 2014, 9:05am UTC](https://discussions.unity.com/t/rotation-using-unity2d/92670/1 "2014-01-14T09:05:33Z")

</div>

I have a game object at the top middle of my screen. I have no idea how to be able to rotate it so it will follow my mouse pointer or even touch position. It doesn’t matter which, I’m currently building it follow my mouse position so let’s stick with coding it “LookAt” my mouse pointer.

If you don’t understand what I want to be able to do, let’s take a look at this simple image.  
 ![20632-rotation.png](https://europe1.discourse-cdn.com/unity/original/3X/4/c/4c081926b78bb5521a0899dc7152ccf192bfa589.png)

The game object (a 2D sprite) should be able to rotate back and forth to point at an x and y coordinate where my mouse pointer is. Every time I tried to use LookRotation or LookAt, I just got weird results that always rotated it incorrect ways. Can somebody help me along here in getting this up and going?

P.S. Preferably in Javascript.

Thanks a ton!

---

<div class="post-metadata">

**Author:** ![kUr4m4](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@kUr4m4](https://discussions.unity.com/u/kUr4m4)\
**Post date:** [January 14, 2014, 10:29am UTC](https://discussions.unity.com/t/rotation-using-unity2d/92670/2 "2014-01-14T10:29:49Z")

</div>

are you looking for Transform.LookAt maybe?

> **[Unity - Scripting API: Transform.LookAt](https://docs.unity3d.com/ScriptReference/Transform.LookAt.html)**

---

<div class="post-metadata">

**Author:** ![BillyM148](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@BillyM148](https://discussions.unity.com/u/BillyM148)\
**Post date:** [January 14, 2014, 10:39am UTC](https://discussions.unity.com/t/rotation-using-unity2d/92670/3 "2014-01-14T10:39:08Z")

</div>

I don’t know enough to know that or not. But i did change

this line -

`transform.rotation = Quaternion.LookRotation(lookDir); `

to this -

`transform.LookAt(lookDir);`

and i still have the same problem with it.

---

<div class="post-metadata">

**Author:** ![Bunny83](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@Bunny83](https://discussions.unity.com/u/Bunny83)\
**Post date:** [January 14, 2014, 11:03am UTC](https://discussions.unity.com/t/rotation-using-unity2d/92670/4 "2014-01-14T11:03:55Z")

</div>

I never used the new 2d features since I stick with unity 4.0 at the moment. However most people forget that LookAt or LookRotation **takes two parameters**. If you don’t pass a second it defaults to Vector3.up which is just a constant for (0, 1, 0).

The **second** parameter controls the rotation **around** the look-at-axis.

LookAt makes the object’s forward axis (z, the blue one) to point directly at the target position (the first parameter). The second parameter just rotates the object around the forward axis so the object’s up axis (y, the green one) points most closely to the given up-vector in the second parameter.

Depending on where “up” is on your object you might want to pass a different up-vector.
