movement no longer uses mouse, fix room cam bug, larger shovel hitbox

This commit is contained in:
2026-02-19 20:08:58 -06:00
parent d2408dabd3
commit 08095945bc
4 changed files with 57 additions and 28 deletions
+40 -14
View File
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
public class CameraController : MonoBehaviour
@@ -19,30 +20,35 @@ public class CameraController : MonoBehaviour
private Vector3 currentCamPosition;
private float desiredCamSize;
private int positionsSet = 0; // this keeps track of how many cam zones we're in
private float timeReturningHome = 0; // how long has the cam been moving home
private List<StaticCamRoom> roomsActive;
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
{
positionsSet++; // we have entered a cam zone
cameraObj.transform.parent = null;
float distanceToMove = Vector3.Distance(this.currentCamPosition, currentCamPosition);
float amountToZoom = Mathf.Abs(this.desiredCamSize - desiredCamSize);
moveSpeed = distanceToMove / camMovementTime;
zoomSpeed = amountToZoom / camMovementTime;
if (currentCamPosition != this.currentCamPosition)
{
cameraObj.transform.parent = null;
isTracking = true;
returningHome = false;
this.currentCamPosition = currentCamPosition;
this.desiredCamSize = desiredCamSize;
float distanceToMove = Vector3.Distance(this.currentCamPosition, currentCamPosition);
float amountToZoom = Mathf.Abs(this.desiredCamSize - desiredCamSize);
moveSpeed = distanceToMove / camMovementTime;
zoomSpeed = amountToZoom / camMovementTime;
isTracking = true;
returningHome = false;
this.currentCamPosition = currentCamPosition;
this.desiredCamSize = desiredCamSize;
}
}
public void ReturnCameraToHome()
{
positionsSet--; // we have exited a cam zone
// if this number is greater than 1, we have left a zone but are still in another
if (positionsSet <= 0)
{
@@ -59,6 +65,11 @@ public void ReturnCameraToHome()
currentCamPosition = playerCamHome.position;
desiredCamSize = baseCamSize;
}
else
{
positionsSet--;
SetCurrentPosition(roomsActive[roomsActive.Count - 1].camPosition.position, roomsActive[roomsActive.Count - 1].camZoom);
}
}
public void AddToRoomsActive(StaticCamRoom room)
@@ -100,9 +111,18 @@ void Update()
{
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);
// Speed up cam if we've been returning home longer than a certain amount
if (timeReturningHome > 1.0f)
{
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed * 1.5f);
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed * 1.5f);
}
else
{
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;
@@ -110,6 +130,12 @@ void Update()
cameraComponent.orthographicSize = baseCamSize;
returningHome = false;
}
timeReturningHome += Time.deltaTime;
}
else
{
timeReturningHome = 0;
}
}
}