Reworked camera handling to be smoother
This commit is contained in:
@@ -16,12 +16,21 @@ public class Controls : MonoBehaviour
|
||||
GameObject playerCam;
|
||||
UIHandler uihandler;
|
||||
Vector3 input;
|
||||
Vector2 view;
|
||||
public PlayerInput playerInput;
|
||||
MoveDirection direction;
|
||||
public Vector2 sensitivityMouse = new Vector2(0, 0);
|
||||
|
||||
float multiplier = 0.01f; //DEV Purpose only
|
||||
private Vector2 lookInput;
|
||||
private Vector2 currentRotation;
|
||||
private Vector2 rotationVelocity;
|
||||
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
private float smoothTime = 0.05f;
|
||||
|
||||
private float minPitch = -75f;
|
||||
private float maxPitch = 80f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -31,7 +40,6 @@ public class Controls : MonoBehaviour
|
||||
playerCam = GameObject.Find("Main Camera");
|
||||
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
|
||||
input = new Vector3();
|
||||
view = new Vector2();
|
||||
playerInput = GetComponent<PlayerInput>();
|
||||
direction = MoveDirection.None;
|
||||
}
|
||||
@@ -53,8 +61,22 @@ public class Controls : MonoBehaviour
|
||||
{
|
||||
if (uihandler.canPlayerRotate())
|
||||
{
|
||||
playerCam.GetComponent<PlayerCamera>().LookAround(view, sensitivityMouse * multiplier);
|
||||
player.GetComponent<PlayerGameObject>().rotate(view, sensitivityMouse * multiplier);
|
||||
lookInput = Mouse.current.delta.ReadValue();
|
||||
Vector2 targetRotation = lookInput * sensitivityMouse * Time.deltaTime;
|
||||
currentRotation = Vector2.SmoothDamp(
|
||||
currentRotation,
|
||||
targetRotation,
|
||||
ref rotationVelocity,
|
||||
smoothTime
|
||||
);
|
||||
|
||||
yaw += currentRotation.x;
|
||||
pitch -= currentRotation.y;
|
||||
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
||||
// Apply rotations
|
||||
transform.rotation = Quaternion.Euler(0f, yaw, 0f);
|
||||
playerCam.GetComponent<PlayerCamera>().LookAround(pitch);
|
||||
player.GetComponent<PlayerGameObject>().rotate(yaw);
|
||||
}
|
||||
if (uihandler.canPlayerMove())
|
||||
{
|
||||
@@ -85,7 +107,7 @@ public class Controls : MonoBehaviour
|
||||
|
||||
public void OnLooking(InputValue value)
|
||||
{
|
||||
view = value.Get<Vector2>();
|
||||
//lookInput = value.Get<Vector2>();
|
||||
}
|
||||
|
||||
public void OnMovement(InputValue value)
|
||||
|
||||
Reference in New Issue
Block a user