Reworked camera handling to be smoother

This commit is contained in:
finnchen123
2026-01-24 14:15:31 +01:00
parent f74ec7e84d
commit 467f6a78e2
5 changed files with 87 additions and 73 deletions

View File

@@ -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)

View File

@@ -43,17 +43,9 @@ namespace Assets.Scripts.Player
return null;
}
public void LookAround(Vector2 view, Vector2 speed)
public void LookAround(float pitch)
{
if (transform.rotation.x <= -0.25)
{
if (view.y > 0) return;
}
if (transform.rotation.x >= 0.25)
{
if (view.y < 0) return;
}
transform.Rotate(Vector3.left, view.y * speed.y);
transform.localRotation = Quaternion.Euler(pitch, 0f, 0f);
}
void showInformation()

View File

@@ -179,8 +179,8 @@ namespace Assets.Scripts.Player
GameObject.Find("QuestLog").GetComponent<QuestLog>().updateQuests("explore", gameObject, 1);
}
public void rotate(Vector2 input, Vector2 speed){
transform.Rotate(Vector3.up, input.x * speed.x * 5);// * Time.deltaTime);
public void rotate(float yaw){
transform.rotation = Quaternion.Euler(0f, yaw, 0f);
}
public void getRotation()