Add Camera controlled by player. #7 (#10)
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>
This commit is contained in:
2023-07-31 19:10:41 -05:00
committed by madxmike
parent 5e894f79e4
commit 3043c54bc4
11 changed files with 931 additions and 4 deletions

View File

@@ -0,0 +1,41 @@
using DefaultNamespace;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Input
{
public class PlayerCameraInputHandler : MonoBehaviour
{
[SerializeField] private PlayerCameraController cameraController;
[SerializeField] [Range(0, 100)] private float rotationSensitivity;
[SerializeField] [Range(0, 1)] private float zoomSensitivity;
private bool _allowRotation;
public void OnInputZoom(InputAction.CallbackContext context)
{
var input = context.ReadValue<float>();
var zoomAmount = input * zoomSensitivity * Time.deltaTime;
cameraController.Zoom(zoomAmount);
}
public void OnInputRotate(InputAction.CallbackContext context)
{
if (context.phase != InputActionPhase.Performed) return;
if (!_allowRotation) return;
var input = context.ReadValue<float>();
var rotationAmount = input * rotationSensitivity * Time.deltaTime;
cameraController.RotateAround(rotationAmount);
}
public void OnInputHoldToRotate(InputAction.CallbackContext context)
{
_allowRotation = context.phase switch
{
InputActionPhase.Performed => true,
_ => false
};
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0b94be55d5ec4fedb531d50297528d3b
timeCreated: 1690824962