# Camera following problem

**URL:** https://discussions.unity.com/t/camera-following-problem/598406
**Category:** Scripting
**Tags:** Scripting
**Created:** [September 21, 2015, 1:27pm UTC](https://discussions.unity.com/t/camera-following-problem/598406 "2015-09-21T13:27:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![StatusQ4](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@StatusQ4](https://discussions.unity.com/u/StatusQ4)
#### Post date: [September 21, 2015, 1:27pm UTC](https://discussions.unity.com/t/camera-following-problem/598406/1 "2015-09-21T13:27:21Z")

</div>

Im making a top down RPG and dont have much experience with scripts, i have 2 Scripts so far one for moving(click to move) and a camera follow script.

This is the click to move script

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

public class moveToClikc : MonoBehaviour {

    public float speed;
    public CharacterController controller;
    private Vector3 position;

    // Use this for initialization
    void Start ()
    {
        position = transform.position;
    }
  
    // Update is called once per frame
    void Update () {

    if(Input.GetMouseButton(0))
        {
            locatePosition();
        }

        moveToPosition();
    }

    void locatePosition()
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if(Physics.Raycast(ray, out hit, 1000))

        {
            position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
        }

    }

    void moveToPosition()
    {
        if (Vector3.Distance(transform.position, position)>2)
        {
            Quaternion newRotation = Quaternion.LookRotation(position - transform.position);

            newRotation.x = 0f;
            newRotation.z = 0f;

            transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.fixedDeltaTime = 10);
            controller.SimpleMove(transform.forward * speed);
        }
    }
}

```

And here is the camera script

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

public class CameraFollow : MonoBehaviour {

    public Transform target;
    public float smoothing = 5f;

    Vector3 offset;

    void Start ()
    {
        offset = transform.position - target.position;
    }

    void FixedUpdate ()
    {
        Vector3 targetCamPos = target.position + offset;
        transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
   
}
    }

```

When I use the Camera script with a simple move script(move with WASD) it works, but when i use the Click to move script the camera script doesn’t work

---

<div class="post-metadata">

### Author: ![LeftyRighty](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@LeftyRighty](https://discussions.unity.com/u/LeftyRighty)
#### Post date: [September 21, 2015, 2:04pm UTC](https://discussions.unity.com/t/camera-following-problem/598406/2 "2015-09-21T14:04:15Z")

</div>

please paste code into the forums and use the `` tags, make it readable, add line numbers etc. (generally people don’t like following links :P), there is a sticky on them at the top of the scripting forum

> [@](#):
>
> camera script doesn’t work

any errors being thrown? did a quick skim and I couldn’t see any obvious problems in there…

---

<div class="post-metadata">

### Author: ![StatusQ4](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@StatusQ4](https://discussions.unity.com/u/StatusQ4)
#### Post date: [September 21, 2015, 2:27pm UTC](https://discussions.unity.com/t/camera-following-problem/598406/3 "2015-09-21T14:27:45Z")

</div>

> [@LeftyRighty](#):
>
> please paste code into the forums and use the `` tags, make it readable, add line numbers etc. (generally people don’t like following links :p), there is a sticky on them at the top of the scripting forum
> 
> any errors being thrown? did a quick skim and I couldn’t see any obvious problems in there…

No errors, when the player moves the camera doesn’t follow, thats all. I have the camera script attached to the camera and the target selected

---

<div class="post-metadata">

### Author: ![StatusQ4](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@StatusQ4](https://discussions.unity.com/u/StatusQ4)
#### Post date: [September 21, 2015, 4:32pm UTC](https://discussions.unity.com/t/camera-following-problem/598406/4 "2015-09-21T16:32:16Z")

</div>

I set the fixedUpdate to just Update in the camera script, now it seems to work
