diff --git a/Assets/Player/Graphs/PlayerBaseFSM.asset b/Assets/Player/Graphs/PlayerBaseFSM.asset index 7f15d7a..835e452 100644 --- a/Assets/Player/Graphs/PlayerBaseFSM.asset +++ b/Assets/Player/Graphs/PlayerBaseFSM.asset @@ -421,7 +421,7 @@ MonoBehaviour: _version: 3.31 _category: _comments: - _translation: {x: 95, y: 259} - _zoomFactor: 0.8928063 + _translation: {x: -36, y: 350} + _zoomFactor: 1 _haltSerialization: 0 _externalSerializationFile: {fileID: 0} diff --git a/Assets/Player/Objects/Player.prefab b/Assets/Player/Objects/Player.prefab index 116a7ab..c0737c0 100644 --- a/Assets/Player/Objects/Player.prefab +++ b/Assets/Player/Objects/Player.prefab @@ -211,15 +211,22 @@ MonoBehaviour: outputMoveDirection: {x: 0, y: 0, z: 0} additionalMoveDirection: {x: 0, y: 0, z: 0} data: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: - value: 1 + value: 2.3 smoothing: 1 easing: 2 currentSmoothing: 0 currentValue: 0 refVel: 0 deaccerlation: - value: 1 + value: 6 smoothing: 1 easing: 2 currentSmoothing: 0 @@ -298,6 +305,13 @@ MonoBehaviour: currentValue: 0 refVel: 0 smoothing: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: value: 0 smoothing: 1 @@ -385,6 +399,13 @@ MonoBehaviour: currentValue: 0 refVel: 0 easing: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: value: 0 smoothing: 1 @@ -472,6 +493,13 @@ MonoBehaviour: currentValue: 0 refVel: 0 defaultData: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: value: 0 smoothing: 1 @@ -559,6 +587,13 @@ MonoBehaviour: currentValue: 0 refVel: 0 defaultSmoothing: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: value: 0 smoothing: 1 @@ -646,6 +681,13 @@ MonoBehaviour: currentValue: 0 refVel: 0 defaultEasing: + moveSmoothing: + value: {x: 0, y: 0} + smoothing: 1 + easing: 2 + currentSmoothing: 0 + currentValue: 0 + refVel: {x: 0, y: 0} acceleration: value: 0 smoothing: 1 diff --git a/Assets/Scripts/Core/Graph Tasks/Movement Settings Changes/ChangeGravitySettings.cs b/Assets/Scripts/Core/Graph Tasks/Movement Settings Changes/ChangeGravitySettings.cs index 50b0c44..3951321 100644 --- a/Assets/Scripts/Core/Graph Tasks/Movement Settings Changes/ChangeGravitySettings.cs +++ b/Assets/Scripts/Core/Graph Tasks/Movement Settings Changes/ChangeGravitySettings.cs @@ -27,19 +27,20 @@ namespace Reset.Units { //Call EndAction() to mark the action as finished, either in success or failure. //EndAction can be called from anywhere. protected override void OnExecute() { - // Jump - FloatValueGroup.UpdateValue(jumpPower, ref agent.data.jumpPower.value, ref agent.defaultData.jumpPower.value); - ValueGroup.ChangeSmoothingEasing(jumpPower, ref agent.data.jumpPower.currentSmoothing, - ref agent.data.jumpPower.easing, ref agent.defaultData.jumpPower.smoothing, ref agent.defaultData.jumpPower.easing); + // Deprecated by unified gravity system, including SetNewGravity + // // Jump + // FloatValueGroup.UpdateValue(jumpPower, ref agent.data.jumpPower.value, ref agent.defaultData.jumpPower.value); + // ValueGroup.ChangeSmoothingEasing(jumpPower, ref agent.data.jumpPower.currentSmoothing, + // ref agent.data.jumpPower.easing, ref agent.defaultData.jumpPower.smoothing, ref agent.defaultData.jumpPower.easing); FloatValueGroup.UpdateValue(jumpPowerDecay, ref agent.data.jumpPowerDecay.value, ref agent.defaultData.jumpPowerDecay.value); ValueGroup.ChangeSmoothingEasing(jumpPowerDecay, ref agent.data.jumpPowerDecay.currentSmoothing, ref agent.data.jumpPowerDecay.easing, ref agent.defaultData.jumpPowerDecay.smoothing, ref agent.defaultData.jumpPowerDecay.easing); - - // Gravity - FloatValueGroup.UpdateValue(gravityPower, ref agent.data.gravityPower.value, ref agent.defaultData.gravityPower.value); - ValueGroup.ChangeSmoothingEasing(gravityPower, ref agent.data.gravityPower.currentSmoothing, - ref agent.data.gravityPower.easing, ref agent.defaultData.gravityPower.smoothing, ref agent.defaultData.gravityPower.easing); + + // Deprecated by SetNewGravity + // FloatValueGroup.UpdateValue(gravityPower, ref agent.data.gravityPower.value, ref agent.defaultData.gravityPower.value); + // ValueGroup.ChangeSmoothingEasing(gravityPower, ref agent.data.gravityPower.currentSmoothing, + // ref agent.data.gravityPower.easing, ref agent.defaultData.gravityPower.smoothing, ref agent.defaultData.gravityPower.easing); FloatValueGroup.UpdateValue(gravityMax, ref agent.data.gravityMax.value, ref agent.defaultData.gravityMax.value); ValueGroup.ChangeSmoothingEasing(gravityMax, ref agent.data.gravityMax.currentSmoothing, diff --git a/Assets/Scripts/Core/MathExtensions.cs b/Assets/Scripts/Core/MathExtensions.cs index 279790c..5ab01ca 100644 --- a/Assets/Scripts/Core/MathExtensions.cs +++ b/Assets/Scripts/Core/MathExtensions.cs @@ -16,4 +16,11 @@ public static class MathExtensions{ public static Color Alpha(this Color input, float newAlpha){ return new Color(input.r, input.g, input.b, newAlpha); } + + public static Vector2 Rotate(this Vector2 v, float delta) { + return new Vector2( + v.x * Mathf.Cos(delta) - v.y * Mathf.Sin(delta), + v.x * Mathf.Sin(delta) + v.y * Mathf.Cos(delta) + ); + } } diff --git a/Assets/Scripts/Player/UnitMovementHandler.cs b/Assets/Scripts/Player/UnitMovementHandler.cs index 4d7f944..1a15a9f 100644 --- a/Assets/Scripts/Player/UnitMovementHandler.cs +++ b/Assets/Scripts/Player/UnitMovementHandler.cs @@ -2,6 +2,7 @@ using System; using UnityEngine; using ParadoxNotion.Design; using PlasticPipe.PlasticProtocol.Messages; +using Reset.Core.Tools; using Sirenix.OdinInspector; public enum PlayerFacingDirection{ @@ -22,6 +23,7 @@ namespace Reset.Units{ [Serializable] public class UnitMovementData : ICloneable{ // Movement Direction + public SettingValue moveSmoothing = new SettingValue(new Vector2(.5f, .5f)); public SettingValue acceleration = new SettingValue(5f); public SettingValue deaccerlation = new SettingValue(5f); @@ -52,7 +54,7 @@ namespace Reset.Units{ } public class ResolvedMovement{ - public UnitMovementHandler.MoveDirection moveDirection; + [ShowInInspector] public UnitMovementHandler.MoveDirection moveDirection; public float moveSpeed; public Quaternion rotation; public float rotationSpeed; @@ -63,23 +65,26 @@ namespace Reset.Units{ public struct MoveDirection{ private Transform owner; - private Vector2 moveDir; // Always local + private Vector2 _moveDir; // Always local public Vector2 World{ - get => owner.TransformDirection(Local); + get => owner.TransformDirection(_moveDir); set{ - moveDir = owner.InverseTransformDirection(value); - Local = moveDir; + _moveDir = owner.InverseTransformDirection(value); } } public Vector2 Local{ - get => owner.InverseTransformDirection(World); + get => _moveDir; set { - moveDir = value; - World = owner.TransformDirection(value); + _moveDir = value; } } + + public MoveDirection(Transform ownerTransform){ + owner = ownerTransform; + _moveDir = Vector2.zero; + } } [ShowInInspector] @@ -130,6 +135,7 @@ namespace Reset.Units{ defaultEasing = (UnitMovementData)easing.Clone(); resolvedMovement = new ResolvedMovement(); + resolvedMovement.moveDirection = new MoveDirection(transform); } void Update(){ @@ -198,57 +204,69 @@ namespace Reset.Units{ // Update the direction, called every frame private void UpdateCurrentDirection(){ // Get input value - Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y); - - // Construct move direction - Vector3 targetDirection = inputMovement; + Vector2 targetDirection = new Vector2(controls.rawMoveInput.x, controls.rawMoveInput.y); // Deadzone - if (inputMovement.magnitude < .05f) { - targetDirection = Vector3.zero; + if (targetDirection.magnitude < .05f) { + targetDirection = Vector2.zero; } - // Remove Y from variables - Vector3 targetNoY = new Vector3(targetDirection.x, 0f, targetDirection.z); - Vector3 currentNoY = new Vector3(outputMoveDirection.x, 0f, outputMoveDirection.z); - + // Get current direction + Vector2 currentDirection = resolvedMovement.moveDirection.Local; + // Also need to find the dot value of the current input versus the current move direction Vector3 slerpedValue; - Vector3 lerpedValue; + Vector2 lerpedValue; + Vector2 newDirection; - float switchedDirection = Vector3.Dot(inputMovement, outputMoveDirection); + float switchedDirection = Vector3.Dot(targetDirection, currentDirection); float switchedDirectionRemapped = Mathf.Lerp(0, 1, switchedDirection); directionChangeDotLerp = Mathf.Lerp(switchedDirection, switchedDirectionRemapped, 5f * Time.deltaTime) ; // turn that .5f into a variable + DebugOverlayDrawer.ChangeValue("Movement", "Direction Change Dot", directionChangeDotLerp); + // Smooth movement. Use deaccel smoothing if the input magnitude is lower, and accel smoothing if it's higher // Also checks when grounded to only use Slerp on the ground - if (targetNoY.magnitude > currentNoY.magnitude) { + if (targetDirection.magnitude > currentDirection.magnitude) { if (controller.isGrounded){ - slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.acceleration.value * Time.deltaTime); - lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.acceleration.value * Time.deltaTime); + slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.acceleration.value * Time.deltaTime); // This used to be a slerp. If rotational movement broke this is why - currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp); + // slerpedValue = Quaternion.AngleAxis(30, Vector3.up) * slerpedValue; + lerpedValue = Vector2.Lerp(currentDirection, targetDirection,data.acceleration.value * Time.deltaTime); + + newDirection = Vector2.Lerp(slerpedValue, slerpedValue, directionChangeDotLerp); + // newDirection = slerpedValue; } else { - currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.acceleration.value * Time.deltaTime); + newDirection = Vector2.Lerp(currentDirection, targetDirection, data.acceleration.value * Time.deltaTime); } } else { if (controller.isGrounded){ - slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.deaccerlation.value * Time.deltaTime); - lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.deaccerlation.value * Time.deltaTime); + slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.deaccerlation.value * Time.deltaTime); // This used to be a slerp. If rotational movement broke this is why + lerpedValue = Vector2.Lerp(currentDirection, targetDirection, data.deaccerlation.value * Time.deltaTime); - currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp); + newDirection = Vector2.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp); } else { - currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.deaccerlation.value * data.airDirectionDecay.value * Time.deltaTime); + newDirection = Vector2.Lerp(currentDirection, targetDirection, data.deaccerlation.value * data.airDirectionDecay.value * Time.deltaTime); } } + + // newDirection = Vector2.MoveTowards(currentDirection, targetDirection.Rotate(-Vector2.Angle(currentDirection, targetDirection)), 2f * Time.deltaTime); // Commit move direction - outputMoveDirection = Vector3.SmoothDamp(outputMoveDirection, new Vector3(currentNoY.x, outputMoveDirection.y, currentNoY.z),ref moveSmoothVelocityRef , .5f *Time.deltaTime); // TODO: Check this smoothing + resolvedMovement.moveDirection.Local = Vector2.SmoothDamp( + resolvedMovement.moveDirection.Local, + newDirection, + ref smoothing.moveSmoothing.refVel, + smoothing.moveSmoothing.smoothing *Time.deltaTime); // TODO: Check this smoothing + + resolvedMovement.moveDirection.Local = newDirection; } // Update the speed, called every frame private void UpdateCurrentSpeed(){ + //TODO: Is accel/deaccel ever used in this file???????? + resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, data.moveSpeed.value, data.moveSpeed.smoothing * Time.deltaTime); } @@ -326,16 +344,16 @@ namespace Reset.Units{ // Move with default settings public void DoMovement(){ - DoMovement(outputMoveDirection, outputSpeed, data.gravityScale.value); // TODO: Gets multiplied a second time in DoMovement by gravity scale???? + DoMovement(resolvedMovement.moveDirection.Local, resolvedMovement.moveSpeed, data.gravityScale.value); // TODO: Gets multiplied a second time in DoMovement by gravity scale???? } // Custom move from input - public void DoMovement(Vector3 moveDir, float speed, float gravityScale){ + public void DoMovement(Vector2 moveDir, float speed, float gravityScale){ // Debug.Log($"moveDir: {moveDir}, agent velocity: {transform.InverseTransformDirection(controller.velocity.normalized)}"); // Seperate the different move directions. Additonal becomes it's own because it needs to be added independently of the other two - Vector3 moveXZDir = new Vector3(moveDir.x, 0f, moveDir.z); - Vector3 moveYDir = new Vector3(0f, resolvedMovement.gravity, 0f); + Vector2 moveXZDir = new Vector3(moveDir.x, moveDir.y); + float moveYDir = resolvedMovement.gravity; Vector3 addDir = additionalMoveDirection; // Add their related speeds @@ -344,7 +362,7 @@ namespace Reset.Units{ addDir *= additionalSpeed * Time.deltaTime; // Construct the direction and move - Vector3 finalDir = moveXZDir + moveYDir; + Vector3 finalDir = new Vector3(moveXZDir.x, moveYDir,moveXZDir.y) ; controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir) + addDir); }