movement no longer uses mouse, fix room cam bug, larger shovel hitbox
This commit is contained in:
@@ -2579,7 +2579,7 @@ SphereCollider:
|
|||||||
m_ProvidesContacts: 0
|
m_ProvidesContacts: 0
|
||||||
m_Enabled: 0
|
m_Enabled: 0
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_Radius: 0.35
|
m_Radius: 0.78
|
||||||
m_Center: {x: 0, y: -0.5, z: 0}
|
m_Center: {x: 0, y: -0.5, z: 0}
|
||||||
--- !u!114 &666997941
|
--- !u!114 &666997941
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Unity.VisualScripting;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class CameraController : MonoBehaviour
|
public class CameraController : MonoBehaviour
|
||||||
@@ -19,30 +20,35 @@ public class CameraController : MonoBehaviour
|
|||||||
private Vector3 currentCamPosition;
|
private Vector3 currentCamPosition;
|
||||||
private float desiredCamSize;
|
private float desiredCamSize;
|
||||||
private int positionsSet = 0; // this keeps track of how many cam zones we're in
|
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;
|
private List<StaticCamRoom> roomsActive;
|
||||||
|
|
||||||
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
|
public void SetCurrentPosition(Vector3 currentCamPosition, float desiredCamSize)
|
||||||
{
|
{
|
||||||
positionsSet++; // we have entered a cam zone
|
positionsSet++; // we have entered a cam zone
|
||||||
cameraObj.transform.parent = null;
|
|
||||||
|
|
||||||
float distanceToMove = Vector3.Distance(this.currentCamPosition, currentCamPosition);
|
if (currentCamPosition != this.currentCamPosition)
|
||||||
float amountToZoom = Mathf.Abs(this.desiredCamSize - desiredCamSize);
|
{
|
||||||
moveSpeed = distanceToMove / camMovementTime;
|
cameraObj.transform.parent = null;
|
||||||
zoomSpeed = amountToZoom / camMovementTime;
|
|
||||||
|
|
||||||
isTracking = true;
|
float distanceToMove = Vector3.Distance(this.currentCamPosition, currentCamPosition);
|
||||||
returningHome = false;
|
float amountToZoom = Mathf.Abs(this.desiredCamSize - desiredCamSize);
|
||||||
|
moveSpeed = distanceToMove / camMovementTime;
|
||||||
this.currentCamPosition = currentCamPosition;
|
zoomSpeed = amountToZoom / camMovementTime;
|
||||||
this.desiredCamSize = desiredCamSize;
|
|
||||||
|
isTracking = true;
|
||||||
|
returningHome = false;
|
||||||
|
|
||||||
|
this.currentCamPosition = currentCamPosition;
|
||||||
|
this.desiredCamSize = desiredCamSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReturnCameraToHome()
|
public void ReturnCameraToHome()
|
||||||
{
|
{
|
||||||
positionsSet--; // we have exited a cam zone
|
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 this number is greater than 1, we have left a zone but are still in another
|
||||||
if (positionsSet <= 0)
|
if (positionsSet <= 0)
|
||||||
{
|
{
|
||||||
@@ -59,6 +65,11 @@ public void ReturnCameraToHome()
|
|||||||
currentCamPosition = playerCamHome.position;
|
currentCamPosition = playerCamHome.position;
|
||||||
desiredCamSize = baseCamSize;
|
desiredCamSize = baseCamSize;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
positionsSet--;
|
||||||
|
SetCurrentPosition(roomsActive[roomsActive.Count - 1].camPosition.position, roomsActive[roomsActive.Count - 1].camZoom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddToRoomsActive(StaticCamRoom room)
|
public void AddToRoomsActive(StaticCamRoom room)
|
||||||
@@ -100,9 +111,18 @@ void Update()
|
|||||||
{
|
{
|
||||||
currentCamPosition = playerCamHome.position;
|
currentCamPosition = playerCamHome.position;
|
||||||
|
|
||||||
cameraObj.transform.position = Vector3.MoveTowards(cameraObj.transform.position, currentCamPosition, Time.deltaTime * moveSpeed);
|
// Speed up cam if we've been returning home longer than a certain amount
|
||||||
cameraComponent.orthographicSize = Mathf.MoveTowards(cameraComponent.orthographicSize, desiredCamSize, Time.deltaTime * zoomSpeed);
|
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)
|
if (Vector3.Distance(cameraObj.transform.position, currentCamPosition) < 0.1f)
|
||||||
{
|
{
|
||||||
cameraObj.transform.parent = playerCamHome;
|
cameraObj.transform.parent = playerCamHome;
|
||||||
@@ -110,6 +130,12 @@ void Update()
|
|||||||
cameraComponent.orthographicSize = baseCamSize;
|
cameraComponent.orthographicSize = baseCamSize;
|
||||||
returningHome = false;
|
returningHome = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeReturningHome += Time.deltaTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timeReturningHome = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,21 +36,24 @@ void Update()
|
|||||||
|
|
||||||
void Walk()
|
void Walk()
|
||||||
{
|
{
|
||||||
moveDir = Vector3.zero;
|
float verticalMovement = 0;
|
||||||
|
float horizontalMovement = 0;
|
||||||
if (!characterController.isGrounded)
|
|
||||||
{
|
|
||||||
moveDir.y -= gravity * Time.deltaTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isDigging)
|
if (!isDigging)
|
||||||
{
|
{
|
||||||
Vector3 verticalMovement = DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
|
verticalMovement = Input.GetAxisRaw("Vertical");
|
||||||
Vector3 horizontalMovement = DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
|
horizontalMovement = Input.GetAxisRaw("Horizontal");
|
||||||
moveDir += verticalMovement + horizontalMovement;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
characterController.Move(moveDir);
|
moveDir = new Vector3(horizontalMovement, 0, verticalMovement).normalized;
|
||||||
|
moveDir *= walkSpeed;
|
||||||
|
|
||||||
|
if (!characterController.isGrounded)
|
||||||
|
{
|
||||||
|
moveDir.y = -gravity;
|
||||||
|
}
|
||||||
|
|
||||||
|
characterController.Move(moveDir * Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DigDetector()
|
void DigDetector()
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ private void OnTriggerEnter(Collider other)
|
|||||||
|
|
||||||
if (controller != null)
|
if (controller != null)
|
||||||
{
|
{
|
||||||
controller.SetCurrentPosition(camPosition.position, camZoom);
|
|
||||||
controller.AddToRoomsActive(this);
|
controller.AddToRoomsActive(this);
|
||||||
|
controller.SetCurrentPosition(camPosition.position, camZoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ private void OnTriggerExit(Collider other)
|
|||||||
|
|
||||||
if (controller != null)
|
if (controller != null)
|
||||||
{
|
{
|
||||||
controller.ReturnCameraToHome();
|
|
||||||
controller.RemoveFromRoomsActive(this);
|
controller.RemoveFromRoomsActive(this);
|
||||||
|
controller.ReturnCameraToHome();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user