change: gravity settings functions and deprecation of jump/gravity split

This commit is contained in:
Chris
2025-09-21 13:53:49 -04:00
parent 0fbef6aeee
commit d4231d4f38
5 changed files with 116 additions and 48 deletions

View File

@@ -421,7 +421,7 @@ MonoBehaviour:
_version: 3.31 _version: 3.31
_category: _category:
_comments: _comments:
_translation: {x: 95, y: 259} _translation: {x: -36, y: 350}
_zoomFactor: 0.8928063 _zoomFactor: 1
_haltSerialization: 0 _haltSerialization: 0
_externalSerializationFile: {fileID: 0} _externalSerializationFile: {fileID: 0}

View File

@@ -211,15 +211,22 @@ MonoBehaviour:
outputMoveDirection: {x: 0, y: 0, z: 0} outputMoveDirection: {x: 0, y: 0, z: 0}
additionalMoveDirection: {x: 0, y: 0, z: 0} additionalMoveDirection: {x: 0, y: 0, z: 0}
data: data:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 1 value: 2.3
smoothing: 1 smoothing: 1
easing: 2 easing: 2
currentSmoothing: 0 currentSmoothing: 0
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
deaccerlation: deaccerlation:
value: 1 value: 6
smoothing: 1 smoothing: 1
easing: 2 easing: 2
currentSmoothing: 0 currentSmoothing: 0
@@ -298,6 +305,13 @@ MonoBehaviour:
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
smoothing: smoothing:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 0 value: 0
smoothing: 1 smoothing: 1
@@ -385,6 +399,13 @@ MonoBehaviour:
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
easing: easing:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 0 value: 0
smoothing: 1 smoothing: 1
@@ -472,6 +493,13 @@ MonoBehaviour:
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
defaultData: defaultData:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 0 value: 0
smoothing: 1 smoothing: 1
@@ -559,6 +587,13 @@ MonoBehaviour:
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
defaultSmoothing: defaultSmoothing:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 0 value: 0
smoothing: 1 smoothing: 1
@@ -646,6 +681,13 @@ MonoBehaviour:
currentValue: 0 currentValue: 0
refVel: 0 refVel: 0
defaultEasing: defaultEasing:
moveSmoothing:
value: {x: 0, y: 0}
smoothing: 1
easing: 2
currentSmoothing: 0
currentValue: 0
refVel: {x: 0, y: 0}
acceleration: acceleration:
value: 0 value: 0
smoothing: 1 smoothing: 1

View File

@@ -27,19 +27,20 @@ namespace Reset.Units {
//Call EndAction() to mark the action as finished, either in success or failure. //Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere. //EndAction can be called from anywhere.
protected override void OnExecute() { protected override void OnExecute() {
// Jump // Deprecated by unified gravity system, including SetNewGravity
FloatValueGroup.UpdateValue(jumpPower, ref agent.data.jumpPower.value, ref agent.defaultData.jumpPower.value); // // Jump
ValueGroup.ChangeSmoothingEasing(jumpPower, ref agent.data.jumpPower.currentSmoothing, // FloatValueGroup.UpdateValue(jumpPower, ref agent.data.jumpPower.value, ref agent.defaultData.jumpPower.value);
ref agent.data.jumpPower.easing, ref agent.defaultData.jumpPower.smoothing, ref agent.defaultData.jumpPower.easing); // 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); FloatValueGroup.UpdateValue(jumpPowerDecay, ref agent.data.jumpPowerDecay.value, ref agent.defaultData.jumpPowerDecay.value);
ValueGroup.ChangeSmoothingEasing(jumpPowerDecay, ref agent.data.jumpPowerDecay.currentSmoothing, ValueGroup.ChangeSmoothingEasing(jumpPowerDecay, ref agent.data.jumpPowerDecay.currentSmoothing,
ref agent.data.jumpPowerDecay.easing, ref agent.defaultData.jumpPowerDecay.smoothing, ref agent.defaultData.jumpPowerDecay.easing); ref agent.data.jumpPowerDecay.easing, ref agent.defaultData.jumpPowerDecay.smoothing, ref agent.defaultData.jumpPowerDecay.easing);
// Gravity // Deprecated by SetNewGravity
FloatValueGroup.UpdateValue(gravityPower, ref agent.data.gravityPower.value, ref agent.defaultData.gravityPower.value); // FloatValueGroup.UpdateValue(gravityPower, ref agent.data.gravityPower.value, ref agent.defaultData.gravityPower.value);
ValueGroup.ChangeSmoothingEasing(gravityPower, ref agent.data.gravityPower.currentSmoothing, // ValueGroup.ChangeSmoothingEasing(gravityPower, ref agent.data.gravityPower.currentSmoothing,
ref agent.data.gravityPower.easing, ref agent.defaultData.gravityPower.smoothing, ref agent.defaultData.gravityPower.easing); // 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); FloatValueGroup.UpdateValue(gravityMax, ref agent.data.gravityMax.value, ref agent.defaultData.gravityMax.value);
ValueGroup.ChangeSmoothingEasing(gravityMax, ref agent.data.gravityMax.currentSmoothing, ValueGroup.ChangeSmoothingEasing(gravityMax, ref agent.data.gravityMax.currentSmoothing,

View File

@@ -16,4 +16,11 @@ public static class MathExtensions{
public static Color Alpha(this Color input, float newAlpha){ public static Color Alpha(this Color input, float newAlpha){
return new Color(input.r, input.g, input.b, 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)
);
}
} }

View File

@@ -2,6 +2,7 @@ using System;
using UnityEngine; using UnityEngine;
using ParadoxNotion.Design; using ParadoxNotion.Design;
using PlasticPipe.PlasticProtocol.Messages; using PlasticPipe.PlasticProtocol.Messages;
using Reset.Core.Tools;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
public enum PlayerFacingDirection{ public enum PlayerFacingDirection{
@@ -22,6 +23,7 @@ namespace Reset.Units{
[Serializable] [Serializable]
public class UnitMovementData : ICloneable{ public class UnitMovementData : ICloneable{
// Movement Direction // Movement Direction
public SettingValue<Vector2> moveSmoothing = new SettingValue<Vector2>(new Vector2(.5f, .5f));
public SettingValue<float> acceleration = new SettingValue<float>(5f); public SettingValue<float> acceleration = new SettingValue<float>(5f);
public SettingValue<float> deaccerlation = new SettingValue<float>(5f); public SettingValue<float> deaccerlation = new SettingValue<float>(5f);
@@ -52,7 +54,7 @@ namespace Reset.Units{
} }
public class ResolvedMovement{ public class ResolvedMovement{
public UnitMovementHandler.MoveDirection moveDirection; [ShowInInspector] public UnitMovementHandler.MoveDirection moveDirection;
public float moveSpeed; public float moveSpeed;
public Quaternion rotation; public Quaternion rotation;
public float rotationSpeed; public float rotationSpeed;
@@ -63,23 +65,26 @@ namespace Reset.Units{
public struct MoveDirection{ public struct MoveDirection{
private Transform owner; private Transform owner;
private Vector2 moveDir; // Always local private Vector2 _moveDir; // Always local
public Vector2 World{ public Vector2 World{
get => owner.TransformDirection(Local); get => owner.TransformDirection(_moveDir);
set{ set{
moveDir = owner.InverseTransformDirection(value); _moveDir = owner.InverseTransformDirection(value);
Local = moveDir;
} }
} }
public Vector2 Local{ public Vector2 Local{
get => owner.InverseTransformDirection(World); get => _moveDir;
set { set {
moveDir = value; _moveDir = value;
World = owner.TransformDirection(value);
} }
} }
public MoveDirection(Transform ownerTransform){
owner = ownerTransform;
_moveDir = Vector2.zero;
}
} }
[ShowInInspector] [ShowInInspector]
@@ -130,6 +135,7 @@ namespace Reset.Units{
defaultEasing = (UnitMovementData)easing.Clone(); defaultEasing = (UnitMovementData)easing.Clone();
resolvedMovement = new ResolvedMovement(); resolvedMovement = new ResolvedMovement();
resolvedMovement.moveDirection = new MoveDirection(transform);
} }
void Update(){ void Update(){
@@ -198,57 +204,69 @@ namespace Reset.Units{
// Update the direction, called every frame // Update the direction, called every frame
private void UpdateCurrentDirection(){ private void UpdateCurrentDirection(){
// Get input value // Get input value
Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y); Vector2 targetDirection = new Vector2(controls.rawMoveInput.x, controls.rawMoveInput.y);
// Construct move direction
Vector3 targetDirection = inputMovement;
// Deadzone // Deadzone
if (inputMovement.magnitude < .05f) { if (targetDirection.magnitude < .05f) {
targetDirection = Vector3.zero; targetDirection = Vector2.zero;
} }
// Remove Y from variables // Get current direction
Vector3 targetNoY = new Vector3(targetDirection.x, 0f, targetDirection.z); Vector2 currentDirection = resolvedMovement.moveDirection.Local;
Vector3 currentNoY = new Vector3(outputMoveDirection.x, 0f, outputMoveDirection.z);
// Also need to find the dot value of the current input versus the current move direction // Also need to find the dot value of the current input versus the current move direction
Vector3 slerpedValue; 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); float switchedDirectionRemapped = Mathf.Lerp(0, 1, switchedDirection);
directionChangeDotLerp = Mathf.Lerp(switchedDirection, switchedDirectionRemapped, 5f * Time.deltaTime) ; // turn that .5f into a variable 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 // 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 // Also checks when grounded to only use Slerp on the ground
if (targetNoY.magnitude > currentNoY.magnitude) { if (targetDirection.magnitude > currentDirection.magnitude) {
if (controller.isGrounded){ if (controller.isGrounded){
slerpedValue = Vector3.Slerp(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
lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.acceleration.value * Time.deltaTime);
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 { } else {
currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.acceleration.value * Time.deltaTime); newDirection = Vector2.Lerp(currentDirection, targetDirection, data.acceleration.value * Time.deltaTime);
} }
} else { } else {
if (controller.isGrounded){ if (controller.isGrounded){
slerpedValue = Vector3.Slerp(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 = Vector3.Lerp(currentNoY, targetNoY, data.deaccerlation.value * Time.deltaTime); lerpedValue = Vector2.Lerp(currentDirection, targetDirection, data.deaccerlation.value * Time.deltaTime);
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp); newDirection = Vector2.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp);
} else { } 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 // 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 // Update the speed, called every frame
private void UpdateCurrentSpeed(){ 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); 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 // Move with default settings
public void DoMovement(){ 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 // 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)}"); // 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 // 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); Vector2 moveXZDir = new Vector3(moveDir.x, moveDir.y);
Vector3 moveYDir = new Vector3(0f, resolvedMovement.gravity, 0f); float moveYDir = resolvedMovement.gravity;
Vector3 addDir = additionalMoveDirection; Vector3 addDir = additionalMoveDirection;
// Add their related speeds // Add their related speeds
@@ -344,7 +362,7 @@ namespace Reset.Units{
addDir *= additionalSpeed * Time.deltaTime; addDir *= additionalSpeed * Time.deltaTime;
// Construct the direction and move // 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); controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * finalDir) + addDir);
} }