- Home /
How to change camera view?
when I'm adding an actor to the scene and hit "Play" the camera is always attached to back of the player. I want to make some kind of Limbo style camera. So, I still want the camera to follow the player (the player should always be at the centre of the screen), but I want it to move only along the Y axis.
Can someone help me with that? Thanks!
Answer by Samael_00001 · Jul 25, 2014 at 05:41 PM
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position;
}
// Update is called once per frame
void LateUpdate () {
transform.position = player.transform.position + offset;
}
}
Answer by dsada · Jul 25, 2014 at 07:09 AM
I guess you need the transform.LookAt function that you can use like this:
public class Example : MonoBehaviour{
void Update() {
camera.transform.LookAt(target); // target is your player's transform
}
}
This will make the camera to look the player no matter where you move the camera
Answer by tanoshimi · Jul 25, 2014 at 07:22 AM
No need for any scripting - make the camera a child of the player gameobject (by dragging in the scene hierarchy), adjust its position to the right and rotate it back to look at the player.
Your answer
Follow this Question
Related Questions
Camera stutter when following a RigidBody2D 0 Answers
Smooth camera shift, Lerp? SmoothShift? 2 Answers
Camera gets stuck when cursor is locked 0 Answers
Issue with my camera controls 0 Answers