From 10fe5bfd3ab4d814ac4d5f0215035a720a1ead14 Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Sat, 8 Aug 2020 06:40:01 +0300 Subject: [PATCH] Move camera rotation to Player from LocalPlayer --- Assets/Scripts/Animation/GunInterpolator.cs | 2 +- Assets/Scripts/Players/LocalPlayer.cs | 8 +------- Assets/Scripts/Players/Player.cs | 6 ++++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Animation/GunInterpolator.cs b/Assets/Scripts/Animation/GunInterpolator.cs index bcb7882..bd99d05 100644 --- a/Assets/Scripts/Animation/GunInterpolator.cs +++ b/Assets/Scripts/Animation/GunInterpolator.cs @@ -15,7 +15,7 @@ namespace NeonTea.Quakeball.Animation { private Vector2 TargetLean = Vector2.zero; private void Awake() { - transform.parent = Player.Camera; + transform.parent = Player.Player.CameraRoot; } private void Update() { diff --git a/Assets/Scripts/Players/LocalPlayer.cs b/Assets/Scripts/Players/LocalPlayer.cs index d4ba141..0546947 100644 --- a/Assets/Scripts/Players/LocalPlayer.cs +++ b/Assets/Scripts/Players/LocalPlayer.cs @@ -8,13 +8,10 @@ namespace NeonTea.Quakeball.Players { /// A controller class for a local player. Handles input and updates the relevant components. [RequireComponent(typeof(Player))] public class LocalPlayer : MonoBehaviour { - public Transform Camera; public bool DisableInput = false; public float FullSyncFrequency = 1; - private float Lean = 0; - - private Player Player; + public Player Player { private set; get; } public InputAction LookAction { private set; get; } private InputAction MoveAction; private InputAction CrouchAction; @@ -89,9 +86,6 @@ namespace NeonTea.Quakeball.Players { Vector2 LookInput = LookAction.ReadValue() * Opts.LookSensitivity; Player.Pitch = Mathf.Clamp(Player.Pitch - LookInput.y * (Opts.InvertVerticalLook ? -1 : 1), -90, 90); Player.Yaw += LookInput.x; - float TargetLean = -Vector3.Dot(Player.GroundVelocity / Player.MoveStyle.TargetVelocity, Camera.right) * Player.MoveStyle.LeanDegrees; - Lean = Mathf.Lerp(Lean, TargetLean, 30f * Time.deltaTime); - Camera.localEulerAngles = new Vector3(Player.Pitch, Player.Yaw, Lean); if (Time.time - PreviousPlayerUpdate >= 1f / Player.UpdateFrequency) { PreviousPlayerUpdate = Time.time; diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index 88a6c9e..52560b4 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -30,6 +30,7 @@ namespace NeonTea.Quakeball.Players { [Header("Visuals")] public DesyncLerper[] Lerpables; + public float Lean; [Header("Player rotation status")] /// The pitch of the player's head. @@ -177,6 +178,11 @@ namespace NeonTea.Quakeball.Players { } Body.localRotation = Quaternion.Lerp(Body.localRotation, Quaternion.Euler(0, BodyYaw, 0), 20f * Time.deltaTime); Head.localRotation = Quaternion.Lerp(Head.localRotation, Quaternion.Euler(Pitch, Yaw, 0), 15f * Time.deltaTime); + + float TargetLean = -Vector3.Dot(GroundVelocity / MoveStyle.TargetVelocity, CameraRoot.right) * MoveStyle.LeanDegrees; + Lean = Mathf.Lerp(Lean, TargetLean, 30f * Time.deltaTime); + CameraRoot.localEulerAngles = new Vector3(Pitch, Yaw, Lean); + UpdateMovement(); }