Commit 83098cae authored by Luke A Smith's avatar Luke A Smith

Merge branch 'CameraFollow2' into 'master'

Second Attempt to merge a camera that smoothly follows a player

See merge request !14
parents ec6eef23 6ddfd6ba
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : SingletonBehaviour<CameraFollow>
{
Camera cameraObj;
public float smoothSpeed;
private float MaxHeight;
private float MaxWidth;
private float MinHeight;
private float MinWidth;
private float OZ;
// Use this for initialization
void Start ()
{
cameraObj = Camera.main;
float camHeight = cameraObj.orthographicSize * 2;
float camWidth = cameraObj.aspect * camHeight;
MaxHeight = World.Height - camHeight / 2;
MaxWidth = World.Width - camWidth / 2;
MinHeight = World.Height + camHeight / 2;
MinWidth = World.Width + camHeight / 2;
OZ = cameraObj.transform.position.z;
}
// Update is called once per frame
void Update ()
{
Vector3 targetPOS = Vector3.Lerp(cameraObj.transform.position, transform.position, smoothSpeed * Time.deltaTime);
/*
//camera dimensions and center
float camHeight = cameraObj.orthographicSize * 2;
float camWidth = cameraObj.aspect * camHeight;
if(targetPOS.y + camHeight > World.Height) //if camera is above bounds
{
targetPOS.y = (MaxHeight);
}
if(targetPOS.y - camHeight < World.Height) // if below bounds
{
targetPOS.y = (MinHeight);
}
if(targetPOS.x + camWidth > World.Width) //if right of bounds
{
targetPOS.x = (MaxWidth);
}
if(targetPOS.x - camWidth < World.Width) // if left of bounds
{
targetPOS.x = (MinWidth);
}*/
cameraObj.transform.position = new Vector3(targetPOS.x, targetPOS.y, OZ);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment