I am programing a 2.5 D Spaceshooter game. Unfortunately, I have some problems with the camera.
With this code, my Camera follows only the spaceship.
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
void Start ()
{
offset = transform.position - player.transform.position;
}
void LateUpdate ()
{
transform.position = player.transform.position + offset;
}
}
The camera should slightly follow the spaceship but should not go out of the boundary like this video: https://www.youtube.com/watch?v=2DN3p8aYOKg
Update: Thanks for the answers. Maybe I should specify my question a little bit. On the website: http://gamasutra.com/blogs/ItayKeren/20150511/243083/Scroll_Back_The_Theory_and_Practice_of_Cameras_in_SideScrollers.php#h.elfjc4ap4hpe There is a example with Curb Camera Motion. I want to make a camera-window which pushes the camera position as the player hits the window edge.
Any ideas, how to realize this?