Camera returns to the same position after starting

I made a script for the camera following the player, but then I changed the camera position in the engine, and after I started the game it returned to the same position, what should i do to fix this?

PS: For some specific reasons, I can’t put the main camera as a character child

code:

using UnityEngine;
using SystemCollections;

public class FreeLookCam : MonoBehaviour {

public GameObject player;
private Vector3 offset;

void Start () {

offset=transform.position;

}

void Update () {

transform.position=player.transform.position+offset;

}

I fixed it for you:

using UnityEngine;
using System.Collections;

public class FreeLookCam : MonoBehaviour
{


    public GameObject player;
    private Vector3 offset;


    void Start()
    {


        offset = transform.position-player.transform.position;

    }


    void Update()
    {

        transform.position = player.transform.position + offset;

    }
}

You should use Debug functions in situations like this, they will help you visualise what is your script doing.
In this case you could use Debug.Log and Debug.DrawLine to check each of your vectors.
Also remember to use code tags in forum, it makes your posts more readable.

1 Like