My DIY Camera Follow Script

ok… so this is what i did, i don’t know very well how i did it but it works, i just used some code of a 2D game i’m working on to set a prefab and tag a script to it, you just need to drag ethan prefab and it’ll be done in the unity screen, also the part of rotating the camera with the keyboard is upside down… up is left right is down and such… if you use it you’ll see what i mean.

And i’m still working on setting the camera back to the original position, so if any ideas or suggestions on the code let me know please, i’m still new at this, i varely know any coding so, any help will be much apreciated.

//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour {

public GameObject player;

public Vector3 offset;

// Use this for initialization
void Start ()
{
    offset = transform.position - player.transform.position;
}

// Update is called once per frame
void LateUpdate ()
{
    transform.position = player.transform.position + offset;
    CamRotation();
    
}

public void CamRotation()
{
    if (Input.GetKey(KeyCode.Q))
    {
        transform.Rotate(Vector3.up);
    }
    else if (Input.GetKey(KeyCode.E))
    {
        transform.Rotate(Vector3.down);
    }
    else if (Input.GetKey(KeyCode.F))
    {
        transform.Rotate(Vector3.left);
    }
    else if (Input.GetKey(KeyCode.R))
    {
        transform.Rotate(Vector3.right);
    }
}

}
//

there you go… and as i said before, any help with the camera back to position idea or anything actually, would be much apreciated. n.n

Privacy & Terms