From 9f4597df067a5fa8d86688dd35460a4c52f78589 Mon Sep 17 00:00:00 2001 From: MuhamadAjiW <16521119@mahasiswa.itb.ac.id> Date: Sat, 20 Apr 2024 21:41:17 +0700 Subject: [PATCH] fix: camera smoothing --- Assets/Scripts/Config/GameConfig.cs | 2 +- Assets/Scripts/Core/UI/Camera/CameraMouse.cs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Config/GameConfig.cs b/Assets/Scripts/Config/GameConfig.cs index 549816b0..d907e903 100644 --- a/Assets/Scripts/Config/GameConfig.cs +++ b/Assets/Scripts/Config/GameConfig.cs @@ -6,8 +6,8 @@ public static class GameConfig{ // Movement lerp constants public static readonly float MOVEMENT_SMOOTHING = 0.14f; - public static readonly float MOVEMENT_SMOOTHING_JUMP_SNAPSHOT = 0.14f; public static readonly float ROTATION_SMOOTHING = 720; + public static readonly float CAMERA_MOUSE_VERTICAL_MAX = 60; // Difficulty multipliers private static readonly DifficultyData EasyData = new(){ diff --git a/Assets/Scripts/Core/UI/Camera/CameraMouse.cs b/Assets/Scripts/Core/UI/Camera/CameraMouse.cs index 7465e5ca..347e3c2d 100644 --- a/Assets/Scripts/Core/UI/Camera/CameraMouse.cs +++ b/Assets/Scripts/Core/UI/Camera/CameraMouse.cs @@ -16,12 +16,10 @@ public class CameraMouse : CameraFollowObject { protected void Update(){ if(GameController.instance.IsPaused) return; - transform.forward = offset.normalized; - mouseTurn.x += Input.GetAxis("Mouse X"); mouseTurn.y += Input.GetAxis("Mouse Y"); - mouseTurn.y = Mathf.Clamp(mouseTurn.y, -90f, 90f); + mouseTurn.y = Mathf.Clamp(mouseTurn.y, -GameConfig.CAMERA_MOUSE_VERTICAL_MAX, GameConfig.CAMERA_MOUSE_VERTICAL_MAX); Quaternion rotation = initialRotation; rotation = Quaternion.AngleAxis(-mouseTurn.y, Vector3.right) * rotation; @@ -32,12 +30,13 @@ public class CameraMouse : CameraFollowObject { bool hit = Physics.Linecast(target.position, targetPosition, out RaycastHit hitLocation, 1); if (hit) targetPosition = hitLocation.point; - transform.localRotation = rotation; + targetRotation = rotation; } protected new void FixedUpdate(){ - transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, followingTime); - // transform.localRotation = targetRotation; + transform.forward = offset.normalized; + transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, followingTime); + transform.localRotation = targetRotation; return; } } -- GitLab