Move camera rotation to Player from LocalPlayer

This commit is contained in:
Jens Pitkänen 2020-08-08 06:40:01 +03:00
parent 3ee35707e2
commit 10fe5bfd3a
3 changed files with 8 additions and 8 deletions

View File

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

View File

@ -8,13 +8,10 @@ namespace NeonTea.Quakeball.Players {
/// <summary>A controller class for a local player. Handles input and updates the relevant components.</summary>
[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<Vector2>() * 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;

View File

@ -30,6 +30,7 @@ namespace NeonTea.Quakeball.Players {
[Header("Visuals")]
public DesyncLerper[] Lerpables;
public float Lean;
[Header("Player rotation status")]
/// <summary>The pitch of the player's head.</summary>
@ -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();
}