From 2dcea147291260ddf66bb3319d5800017cb773db Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Mon, 10 Aug 2020 02:27:48 +0300 Subject: [PATCH] Tweak movement --- Assets/GameObjects/Prefabs/LocalPlayer.prefab | 23 ++++++++++ Assets/GameObjects/Prefabs/Player.prefab | 4 +- .../MoveStyles/Crouching.asset | 2 +- .../MoveStyles/Running.asset | 4 +- Assets/Scripts/Animation/GunInterpolator.cs | 4 -- .../Animation/SoldierProceduralAnimator.cs | 5 ++- Assets/Scripts/Players/Player.cs | 44 +++++++++---------- 7 files changed, 52 insertions(+), 34 deletions(-) diff --git a/Assets/GameObjects/Prefabs/LocalPlayer.prefab b/Assets/GameObjects/Prefabs/LocalPlayer.prefab index 6905a04..8e96324 100644 --- a/Assets/GameObjects/Prefabs/LocalPlayer.prefab +++ b/Assets/GameObjects/Prefabs/LocalPlayer.prefab @@ -240,6 +240,24 @@ MonoBehaviour: DisableInput: 0 SyncInterval: 0.5 MovementUpdateInterval: 0.03 +--- !u!114 &3537472584083277103 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7808238467771803924} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 22a7da1b361417640853a9cdcde28400, type: 3} + m_Name: + m_EditorClassIdentifier: + Player: {fileID: 7626229210202316125} + InterpolationSpeed: 5 + YawDegrees: 4 + PitchDegrees: 4 + RollDegrees: 6 + RotationThreshold: 5 --- !u!1 &8414821799312552490 GameObject: m_ObjectHideFlags: 0 @@ -817,3 +835,8 @@ Transform: m_CorrespondingSourceObject: {fileID: 4833458671639168932, guid: 0bffd92c46c257840806f5e957954800, type: 3} m_PrefabInstance: {fileID: 8134536652936637724} m_PrefabAsset: {fileID: 0} +--- !u!1 &7808238467771803924 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2071588178488902664, guid: 0bffd92c46c257840806f5e957954800, type: 3} + m_PrefabInstance: {fileID: 8134536652936637724} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/GameObjects/Prefabs/Player.prefab b/Assets/GameObjects/Prefabs/Player.prefab index f0bd9a7..3023d25 100644 --- a/Assets/GameObjects/Prefabs/Player.prefab +++ b/Assets/GameObjects/Prefabs/Player.prefab @@ -109,7 +109,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1607323028047207915} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: -0.02, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 4103164600241655739} @@ -508,7 +508,7 @@ MonoBehaviour: GroundCastLength: 0.2 GroundLayer: serializedVersion: 2 - m_Bits: 11009 + m_Bits: 10497 ShowGroundCast: 0 ShowMoveVector: 0 --- !u!1 &7391558913556166741 diff --git a/Assets/GameObjects/ScriptableObjects/MoveStyles/Crouching.asset b/Assets/GameObjects/ScriptableObjects/MoveStyles/Crouching.asset index e2d3390..15312e5 100644 --- a/Assets/GameObjects/ScriptableObjects/MoveStyles/Crouching.asset +++ b/Assets/GameObjects/ScriptableObjects/MoveStyles/Crouching.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_Name: Crouching m_EditorClassIdentifier: TargetVelocity: 6 - StopVelocity: 3 + StopVelocity: 4 Acceleration: 20 AirAcceleration: 15 Friction: 20 diff --git a/Assets/GameObjects/ScriptableObjects/MoveStyles/Running.asset b/Assets/GameObjects/ScriptableObjects/MoveStyles/Running.asset index 148f276..e650eb9 100644 --- a/Assets/GameObjects/ScriptableObjects/MoveStyles/Running.asset +++ b/Assets/GameObjects/ScriptableObjects/MoveStyles/Running.asset @@ -13,8 +13,8 @@ MonoBehaviour: m_Name: Running m_EditorClassIdentifier: TargetVelocity: 11 - StopVelocity: 3 - Acceleration: 7 + StopVelocity: 6 + Acceleration: 9 AirAcceleration: 5 Friction: 6 AirFriction: 2 diff --git a/Assets/Scripts/Animation/GunInterpolator.cs b/Assets/Scripts/Animation/GunInterpolator.cs index bd99d05..0db4733 100644 --- a/Assets/Scripts/Animation/GunInterpolator.cs +++ b/Assets/Scripts/Animation/GunInterpolator.cs @@ -14,10 +14,6 @@ namespace NeonTea.Quakeball.Animation { private Vector2 CurrentLean = Vector2.zero; private Vector2 TargetLean = Vector2.zero; - private void Awake() { - transform.parent = Player.Player.CameraRoot; - } - private void Update() { Vector2 LookDelta = Player.LookAction.ReadValue(); SetTarget(LookDelta.x, ref TargetLean.x); diff --git a/Assets/Scripts/Animation/SoldierProceduralAnimator.cs b/Assets/Scripts/Animation/SoldierProceduralAnimator.cs index 127ea99..9cb9eb0 100644 --- a/Assets/Scripts/Animation/SoldierProceduralAnimator.cs +++ b/Assets/Scripts/Animation/SoldierProceduralAnimator.cs @@ -21,9 +21,9 @@ namespace NeonTea.Quakeball.Animation { public Transform GunHandle; private Animator Animator; - private float BodyYaw = 0; private Transform BehindHand; private Transform FrontHand; + private Transform Head; private void Awake() { foreach (Animator animator in Soldiers) { @@ -31,7 +31,7 @@ namespace NeonTea.Quakeball.Animation { } Animator = Soldiers[(int)Model].GetComponent(); Animator.gameObject.SetActive(true); - HeadCollider.parent = TransformUtil.FindChildWithName(Animator.transform, "HEAD"); + HeadCollider.parent = Head = TransformUtil.FindChildWithName(Animator.transform, "HEAD"); BehindHand = TransformUtil.FindChildWithName(Animator.transform, "HAND.R"); FrontHand = TransformUtil.FindChildWithName(Animator.transform, "HAND.L"); if (GunGluedToHand) { @@ -48,6 +48,7 @@ namespace NeonTea.Quakeball.Animation { private void LateUpdate() { transform.localEulerAngles = new Vector3(0, Player.Yaw, 0); + Head.localEulerAngles = new Vector3(Player.Pitch, 0, 0); if (GunGluedToHand) { Vector3 GunOffset = GunHandle.position - Gun.position; diff --git a/Assets/Scripts/Players/Player.cs b/Assets/Scripts/Players/Player.cs index 54c0300..55543f0 100644 --- a/Assets/Scripts/Players/Player.cs +++ b/Assets/Scripts/Players/Player.cs @@ -133,19 +133,6 @@ namespace NeonTea.Quakeball.Players { return ShouldApply; } - /// The normal of the ground below the player. If there is no ground, it's Vector3.up by default. - public Vector3 GroundCast() { - RaycastHit Hit; - if (ShowGroundCast) { - Debug.DrawLine(FeetPosition, FeetPosition - Vector3.up, Color.red, 1f); - } - if (Physics.Raycast(FeetPosition, -Vector3.up, out Hit, GroundCastLength, GroundLayer)) { - return Hit.normal; - } else { - return Vector3.up; - } - } - public bool Jump() { bool IsCoyoteTime = Time.time - GroundedTime <= CoyoteTime + PingBias; if (IsCoyoteTime || IsGrounded()) { @@ -249,6 +236,20 @@ namespace NeonTea.Quakeball.Players { return CharacterController.isGrounded && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0; } + /// The normal of the ground below the player. If there is no ground, it's Vector3.up by default. + private Vector3 GroundCast() { + RaycastHit hit; + Vector3 feetPosition = FeetPosition + transform.position + CharacterController.center + Vector3.down * CharacterController.height / 2; + if (ShowGroundCast) { + Debug.DrawLine(feetPosition, feetPosition - Vector3.up, Color.red, 1f); + } + if (Physics.Raycast(feetPosition, -Vector3.up, out hit, GroundCastLength, GroundLayer)) { + return hit.normal; + } else { + return Vector3.up; + } + } + private void Awake() { CharacterController = GetComponent(); FeetPosition = transform.position + CharacterController.center - Vector3.up * (CharacterController.height / 2 + CharacterController.skinWidth / 2); @@ -278,7 +279,7 @@ namespace NeonTea.Quakeball.Players { bool FallingDown = Vector3.Dot(Vector3.down, GravitationalVelocity) > 0; if (Grounded && FallingDown) { - GravitationalVelocity = Vector3.zero; + GravitationalVelocity = GroundCastLength * Vector3.down; } else if (!Grounded) { GravitationalVelocity += Physics.gravity * Time.deltaTime; } @@ -305,22 +306,19 @@ namespace NeonTea.Quakeball.Players { Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed); GroundVelocity += FixedHeading * Acceleration; - Vector3 FinalMoveVector = GroundVelocity + GravitationalVelocity; - CharacterController.Move(FinalMoveVector * Time.deltaTime); + CharacterController.Move(GroundVelocity * Time.deltaTime); + CollisionFlags flags = CharacterController.Move(GravitationalVelocity * Time.deltaTime); if (CharacterController.isGrounded) { GroundedTime = Time.time; LatestGroundedY = transform.position.y; } if (GravitationalVelocity.y > 0.1 && Mathf.Abs(CharacterController.velocity.y) < 0.1) { - // Hit a roof while jumping - GravitationalVelocity.y = 0; + // Hit a roof while jumping, reset falling velocity downwards (same as "static gravity" when grounded) + GravitationalVelocity.y = GroundCastLength; } if (ShowMoveVector) { - Debug.DrawLine( - transform.position + CharacterController.center, - transform.position + CharacterController.center + FinalMoveVector, - Color.green, 1.0f - ); + Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GravitationalVelocity, Color.yellow, 1.0f); + Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GroundVelocity, Color.green, 1.0f); } float TargetBobbiness = Grounded ? GroundVelocity.magnitude / MoveStyle.TargetVelocity : 0;