# Converted MouseLook from C# to Java problems

**URL:** <https://discussions.unity.com/t/converted-mouselook-from-c-to-java-problems/29641>\
**Category:** Questions & Answers\
**Created:** [October 6, 2011, 6:26pm UTC](https://discussions.unity.com/t/converted-mouselook-from-c-to-java-problems/29641 "2011-10-06T18:26:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slayer29179](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@slayer29179](https://discussions.unity.com/u/slayer29179)\
**Post date:** [October 6, 2011, 6:26pm UTC](https://discussions.unity.com/t/converted-mouselook-from-c-to-java-problems/29641/1 "2011-10-06T18:26:59Z")

</div>

Hey, sorry to keep posting but 😕 problem and this one has struck me big time, it works perfect looking up and down but i cannot look left or right so that also stops diagonal 😕 i used this code [unifycommunity.com](http://www.unifycommunity.com/wiki/index.php?title=MouseLookPlus) and change it because they said we could in the notes but help this is my code thank you in advance to whoever fixes it

```
enum Axes {MouseXandY, MouseX, MouseY}
var Axis : Axes = Axes.MouseXandY;

var sensitivityX = 15.0;
var sensitivityY = 15.0;

var rotationX = 0.0;
var rotationY = 0.0;

function Update ()
{
    if (Axis == Axes.MouseXandY)
    {
        // Read the mouse input axis
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    }
    else if (Axis == Axes.MouseX)
    {
        // Read the mouse input axis
        rotationX -= Input.GetAxis("Mouse X") * sensitivityX;
    }
    else if (Axis == Axes.MouseY)
    {
        // Read the mouse input axis
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    }
}

```

please help it looks like it should work to me because they are both the same as y except has changed please help thank you

---

<div class="post-metadata">

**Author:** ![aldonaletto](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/aldonaletto/32/44226_2.png) [@aldonaletto](https://discussions.unity.com/u/aldonaletto)\
**Post date:** [October 7, 2011, 12:00am UTC](https://discussions.unity.com/t/converted-mouselook-from-c-to-java-problems/29641/2 "2011-10-07T00:00:27Z")

</div>

There’s one instruction missing - just the most important, the last one in Update:

```
...
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    }
    // this instruction was missing:
    transform.localEulerAngles = Vector3(rotationY, rotationX, 0);
}
```

With this instruction, this MouseLook works perfectly in all modes. Try it and let me know if you still have problems.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)\
**Post date:** [January 14, 2012, 1:16am UTC](https://discussions.unity.com/t/converted-mouselook-from-c-to-java-problems/29641/3 "2012-01-14T01:16:05Z")

</div>

hate to bust in here but you forgot to limit the rotation. (please note that this is reference to anyone else who may be looking for this later on

```
enum Axes {MouseXandY, MouseX, MouseY}
var Axis : Axes = Axes.MouseXandY;

var sensitivityX = 15.0;
var sensitivityY = 15.0;

var rotationX = 0.0;
var rotationY = 0.0;

var minimumY :float = -60F;
var maximumY :float = 60F;

var minimumX :float = -360F;
var maximumX :float = 360F;

function Update ()
{
    if (Axis == Axes.MouseXandY)
    {
        // Read the mouse input axis
        rotationX += Input.GetAxis("Mouse X") * -sensitivityX;
        rotationY += Input.GetAxis("Mouse Y") * -sensitivityY;
    }
    else if (Axis == Axes.MouseX)
    {
        // Read the mouse input axis
        rotationX -= Input.GetAxis("Mouse X") * -sensitivityX;
        //rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
    }
    else if (Axis == Axes.MouseY)
    {
        // Read the mouse input axis
        rotationY += Input.GetAxis("Mouse Y") * -sensitivityY;
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    }
    transform.localEulerAngles = Vector3(rotationY, rotationX, 0);
}
```

I annotated the limit x because I had no need for it in my code
