Michael
3043c54bc4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Adds the player camera as described in #7. As a note for the future that I forgot to add as a comment here, the camera zoom and rotation should be tweened to give a smoother effect. Reviewed-on: #10 Reviewed-by: zephyr <zephyr@noreply.localhost> Co-authored-by: Michael <mep053@gmail.com> Co-committed-by: Michael <mep053@gmail.com>
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace DefaultNamespace
|
|
{
|
|
public class PlayerCameraController : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform logicalCamera;
|
|
[SerializeField] private Transform physicalCamera;
|
|
|
|
[SerializeField] private Transform pivot;
|
|
[SerializeField] private Transform minZoomTarget;
|
|
[SerializeField] private Transform maxZoomTarget;
|
|
|
|
private float _zoomAmount;
|
|
|
|
/// <summary>
|
|
/// Rotates the logical camera around the pivot by angle degrees.
|
|
/// </summary>
|
|
/// <param name="angle">The amount to rotate, in degrees</param>
|
|
public void RotateAround(float angle)
|
|
{
|
|
logicalCamera.RotateAround(pivot.position, Vector3.up, angle);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lerps the physical camera between the min zoom target and the max zoom target by the current zoom + amount
|
|
/// </summary>
|
|
/// <param name="amount"></param>
|
|
public void Zoom(float amount)
|
|
{
|
|
_zoomAmount = Mathf.Clamp01(_zoomAmount + amount);
|
|
physicalCamera.localPosition = Vector3.Lerp(minZoomTarget.localPosition, maxZoomTarget.localPosition, _zoomAmount);
|
|
}
|
|
}
|
|
} |