add camera position switching for static view rooms

This commit is contained in:
2026-01-12 21:15:03 -06:00
parent 8eea154717
commit 6baa6956bf
23 changed files with 11034 additions and 26 deletions
+68
View File
@@ -0,0 +1,68 @@
using UnityEngine;
public class CameraController : MonoBehaviour
{
private float moveSpeed = 50.0f;
private float zoomSpeed = 20.0f;
private bool isTracking = false; // don't track when parented
private bool returningHome = false; // cam is on its way home
private float baseCamSize = 5; // this is how "zoomed" the ortho cam is
public Transform playerCamHome; // camera's home base
public GameObject cameraObj;
private Camera cameraComponent;
private Vector3 currentCamPosition;
private float desiredCamSize;
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
{
isTracking = true;
returningHome = false;
cameraObj.transform.parent = null;
this.currentCamPosition = currentCamPosition;
this.desiredCamSize = desiredCamSize;
}
public void ReturnCameraToHome()
{
isTracking = false;
returningHome = true;
currentCamPosition = playerCamHome.position;
desiredCamSize = baseCamSize;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
cameraComponent = cameraObj.GetComponent<Camera>();
ReturnCameraToHome();
}
// Update is called once per frame
void Update()
{
if (isTracking)
{
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed);
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed);
}
if (returningHome)
{
currentCamPosition = playerCamHome.position;
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed);
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed);
if (Vector3.Distance(cameraObj.transform.position, currentCamPosition) < 0.1f)
{
cameraObj.transform.parent = playerCamHome;
cameraObj.transform.localPosition = Vector3.zero;
cameraComponent.orthographicSize = baseCamSize;
returningHome = false;
}
}
}
}