working on fpp locomotion, camera spring
This commit is contained in:
59
Assets/jelycho/Code/Player/FPPCamera.cs
Normal file
59
Assets/jelycho/Code/Player/FPPCamera.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using RebootKit.Engine.Foundation;
|
||||
using RebootKit.Engine.Services.Simulation.Sensors;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RealityReboot.jelycho.Player {
|
||||
[AddComponentMenu(GameConsts.k_AddComponentMenu + "Player/First Person Camera")]
|
||||
public class FPPCamera : MonoBehaviour {
|
||||
[ConfigVar("fpp.camera.fov", 60.0f, "Field of view for the first person camera.")]
|
||||
static ConfigVar s_cameraFOV;
|
||||
|
||||
[SerializeField] float _pickDistance = 5.0f;
|
||||
|
||||
[SerializeField] LayerMask _pickLayer;
|
||||
|
||||
[field: SerializeField]
|
||||
public float Sensitivity { get; set; }
|
||||
|
||||
[SerializeField] float _pitchMin = -80f;
|
||||
|
||||
[SerializeField] float _pitchMax = 80f;
|
||||
|
||||
[field: SerializeField]
|
||||
public CinemachineCamera Camera { get; private set; }
|
||||
|
||||
readonly RaycastSensor _raycastSensor = new();
|
||||
|
||||
public float Pitch { get; private set; }
|
||||
public float Yaw { get; private set; }
|
||||
|
||||
public ISensor Sensor {
|
||||
get {
|
||||
_raycastSensor.ray = new Ray(Camera.transform.position, Camera.transform.forward);
|
||||
_raycastSensor.maxDistance = _pickDistance;
|
||||
_raycastSensor.layerMask = _pickLayer;
|
||||
return _raycastSensor;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick() {
|
||||
Camera.Lens.FieldOfView = s_cameraFOV.FloatValue;
|
||||
Camera.transform.localRotation = Quaternion.Euler(Pitch, 0f, 0f);
|
||||
}
|
||||
|
||||
public void Rotate(float x, float y) {
|
||||
float sens = Sensitivity;
|
||||
|
||||
Pitch -= y * sens;
|
||||
Pitch = Mathf.Clamp(Pitch, _pitchMin, _pitchMax);
|
||||
|
||||
Yaw += x * sens;
|
||||
}
|
||||
|
||||
public void SetLookDirection(Vector3 forward) {
|
||||
Pitch = Mathf.Asin(-forward.y) * Mathf.Rad2Deg;
|
||||
Yaw = Mathf.Atan2(forward.x, forward.z) * Mathf.Rad2Deg;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user