# Weird Controls

**URL:** https://discussions.unity.com/t/weird-controls/595487
**Category:** Scripting
**Tags:** Scripting
**Created:** [August 29, 2015, 3:35pm UTC](https://discussions.unity.com/t/weird-controls/595487 "2015-08-29T15:35:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Glemau](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Glemau](https://discussions.unity.com/u/Glemau)
#### Post date: [August 29, 2015, 3:35pm UTC](https://discussions.unity.com/t/weird-controls/595487/1 "2015-08-29T15:35:34Z")

</div>

Hi everyone,

My Character Controller is acting weird.  
When I look forward it goes forward.  
When I look sideways it goes sideways.  
When I look Backwards it goes Backwards.  
Heres my mouseLook Script(attached to the Camera, Child of my actual player.):

```csharp
usingUnityEngine;

//VerysimplesmoothmouselookmodifierfortheMainCamerainUnity
//byFrancisR. Griffiths-Keam - www.runningdimensions.com

[AddComponentMenu("Camera/Simple Smooth Mouse Look ")]
publicclassMouseLook : MonoBehaviour
{
Vector2_mouseAbsolute;
Vector2_smoothMouse;

publicVector2clampInDegrees = newVector2(360, 180);
publicboollockCursor;
publicVector2sensitivity = newVector2(2, 2);
publicVector2smoothing = newVector2(3, 3);
publicVector2targetDirection;
publicVector2targetCharacterDirection;

//Assignthisifthere'saparentobjectcontrollingmotion, suchasaCharacterController.
//Yawrotationwillaffectthisobjectinsteadofthecameraifset.
publicGameObjectcharacterBody;

voidStart()
{
//Settargetdirectiontothecamera'sinitialorientation.
targetDirection = transform.localRotation.eulerAngles;

//Settargetdirectionforthecharacterbodytoitsinitalstate.
if (characterBody) targetCharacterDirection = characterBody.transform.localRotation.eulerAngles;
}

voidUpdate()
{
//Ensurethecursorisalwayslockedwhenset
Screen.lockCursor = lockCursor;

//Allowthescripttoclampbasedonadesiredtargetvalue.
vartargetOrientation = Quaternion.Euler(targetDirection);
vartargetCharacterOrientation = Quaternion.Euler(targetCharacterDirection);

//Getrawmouseinputforacleanerreadingonmoresensitivemice.
varmouseDelta = newVector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

//Scaleinputagainstthesensitivitysettingandmultiplythatagainstthesmoothingvalue.
mouseDelta = Vector2.Scale(mouseDelta, newVector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y));

//Interpolatemousemovementovertimetoapplysmoothingdelta.
_smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x);
_smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y);

//Findtheabsolutemousemovementvaluefrompointzero.
_mouseAbsolute += _smoothMouse;

//Clampandapplythelocalxvaluefirst, soasnottobeaffectedbyworldtransforms.
if (clampInDegrees.x < 360)
_mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f);

varxRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right);
transform.localRotation = xRotation;

//Thenclampandapplytheglobalyvalue.
if (clampInDegrees.y < 360)
_mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f);

transform.localRotation *= targetOrientation;

//Ifthere'sacharacterbodythatactsasaparenttothecamera
if (characterBody)
{
varyRotation = Quaternion.AngleAxis(_mouseAbsolute.x, characterBody.transform.up);
characterBody.transform.localRotation = yRotation;
characterBody.transform.localRotation *= targetCharacterOrientation;
}
else
{
varyRotation = Quaternion.AngleAxis(_mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up));
transform.localRotation *= yRotation;
}
}
}

```

And my movement scripts(attached to the player character):

```csharp
using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    public Transform Trans;
    public Rigidbody rb;
    public int moveSpeed;
    public int sprintIncrease;
    public int strafeSpeed;

    // Use this for initialization
    void Start ()
    {
        Trans = gameObject.GetComponent<Transform>();
        rb = gameObject.GetComponent<Rigidbody> ();
    }
   
    // Update is called once per frame
    void Update () {

        if (Input.GetKey (KeyCode.W))
        {
            rb.transform.Translate(transform.forward*moveSpeed*Time.deltaTime);
        }
        if (Input.GetKey (KeyCode.D))
        {
            rb.transform.Translate(transform.right*strafeSpeed*Time.deltaTime);
        }
        if (Input.GetKey (KeyCode.A))
        {
            rb.transform.Translate(-transform.right*strafeSpeed*Time.deltaTime);
        }
        if (Input.GetKey (KeyCode.S))
        {
            rb.transform.Translate(-transform.forward*strafeSpeed*Time.deltaTime);
        }
        if (Input.GetKey (KeyCode.LeftShift))
        {
            rb.transform.Translate(transform.forward*moveSpeed*sprintIncrease*Time.deltaTime);
        }
        if (Input.GetKeyDown (KeyCode.Space))
        {
            rb.AddForce(0,500,0);
        }

    }
}

```

Hope You can help.

~Glemau

---

<div class="post-metadata">

### Author: ![Kiwasi](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kiwasi/32/351502_2.png) [@Kiwasi](https://discussions.unity.com/u/Kiwasi)
#### Post date: [August 29, 2015, 3:43pm UTC](https://discussions.unity.com/t/weird-controls/595487/2 "2015-08-29T15:43:16Z")

</div>

> [@Glemau](#):
>
> When I look forward it goes forward.  
> When I look sideways it goes sideways.  
> When I look Backwards it goes Backwards.

This must mean I’m up far to late. I’m not seeing the problem.

Isn’t this desired behaviour? Or do you want the player to move in a direction they are not facing?

A quick description of what should happen will help.

Edit: pro tip: you are allowed to put spaces in your comments.

---

<div class="post-metadata">

### Author: ![gorbit99](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gorbit99/32/551958_2.png) [@gorbit99](https://discussions.unity.com/u/gorbit99)
#### Post date: [August 29, 2015, 6:14pm UTC](https://discussions.unity.com/t/weird-controls/595487/3 "2015-08-29T18:14:19Z")

</div>

> [@Kiwasi](#):
>
> Edit: pro tip: you are allowed to put spaces in your comments.

Yeah, that would be great 🙂 It looks like those find the words puzzles

---

<div class="post-metadata">

### Author: ![Glemau](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Glemau](https://discussions.unity.com/u/Glemau)
#### Post date: [September 19, 2015, 11:51am UTC](https://discussions.unity.com/t/weird-controls/595487/4 "2015-09-19T11:51:49Z")

</div>

> [@Kiwasi](#):
>
> This must mean I’m up far to late. I’m not seeing the problem.
> 
> Isn’t this desired behaviour? Or do you want the player to move in a direction they are not facing?
> 
> A quick description of what should happen will help.
> 
> Edit: pro tip: you are allowed to put spaces in your comments.

So I mean the player moves sideways from where i look. So he doesn’t move in the direction the camera is looking
