changed: changing some air movement values can now be smoothed (including values that are used to smoothing out inputs)

This commit is contained in:
Chris
2025-08-21 17:29:22 -04:00
parent 93634a9586
commit a289c78b5d
7 changed files with 337 additions and 145 deletions

View File

@@ -0,0 +1,32 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a686a47eee2fa44cb0a34b5d86e4d5e, type: 3}
m_Name: PlayerMovementResetTriggerBT
m_EditorClassIdentifier:
_serializedGraph: '{"type":"NodeCanvas.BehaviourTrees.BehaviourTree","nodes":[{"_position":{"x":642.0779,"y":186.1875},"$type":"NodeCanvas.BehaviourTrees.Sequencer","$id":"0"},{"_condition":{"eventName":{"_value":"Delay
Air Movement Reset"},"saveEventValue":{"_name":"_delay"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent`1[[System.Single,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"_position":{"x":340.0,"y":408.0},"$type":"NodeCanvas.BehaviourTrees.ConditionNode","$id":"1"},{"policy":1,"dynamic":true,"_position":{"x":840.0,"y":403.0},"$type":"NodeCanvas.BehaviourTrees.Parallel","$id":"2"},{"_condition":{"eventName":{"_value":"Delay
Air Movement Reset"},"saveEventValue":{"_name":"_delay"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent`1[[System.Single,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"_position":{"x":592.0,"y":594.0},"$type":"NodeCanvas.BehaviourTrees.Interruptor","$id":"3"},{"_condition":{"timeout":{"_name":"_delay"},"$type":"NodeCanvas.Tasks.Conditions.Timeout"},"_position":{"x":710.0,"y":739.0},"$type":"NodeCanvas.BehaviourTrees.WaitUntil","$id":"4"},{"repeaterMode":1,"repeatTimes":{"_value":1},"_position":{"x":755.0,"y":853.0},"$type":"NodeCanvas.BehaviourTrees.Repeater","$id":"5"},{"_position":{"x":764.0,"y":956.0},"$type":"NodeCanvas.BehaviourTrees.Sequencer","$id":"6"},{"_action":{"eventName":{"_value":"Reset
Air Movement"},"eventValue":{"_value":1.0},"delay":{},"$type":"NodeCanvas.Tasks.Actions.SendEvent`1[[System.Single,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"},"_position":{"x":571.0,"y":1106.0},"$type":"NodeCanvas.BehaviourTrees.ActionNode","$id":"7"},{"_condition":{"eventName":{"_value":"Air
Reset Received"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent"},"_position":{"x":824.0,"y":1105.0},"$type":"NodeCanvas.BehaviourTrees.ConditionNode","$id":"8"},{"_condition":{"eventName":{"_value":"Cancel
Air Movement Reset"},"$type":"NodeCanvas.Tasks.Conditions.CheckEvent"},"_position":{"x":955.4977,"y":598.6238},"$type":"NodeCanvas.BehaviourTrees.ConditionNode","$id":"9"}],"connections":[{"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"1"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"0"},"_targetNode":{"$ref":"2"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"3"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"2"},"_targetNode":{"$ref":"9"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"3"},"_targetNode":{"$ref":"4"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"4"},"_targetNode":{"$ref":"5"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"5"},"_targetNode":{"$ref":"6"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"6"},"_targetNode":{"$ref":"7"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"},{"_sourceNode":{"$ref":"6"},"_targetNode":{"$ref":"8"},"$type":"NodeCanvas.BehaviourTrees.BTConnection"}],"canvasGroups":[],"localBlackboard":{"_variables":{}},"derivedData":{"repeat":true,"$type":"NodeCanvas.BehaviourTrees.BehaviourTree+DerivedSerializationData"}}'
_objectReferences: []
_graphSource:
_version: 3.31
_category:
_comments:
_translation: {x: -82, y: -349}
_zoomFactor: 1
_haltSerialization: 0
_externalSerializationFile: {fileID: 0}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 26340c3b8bba95c4396860ccfc2cd444
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@@ -147,7 +147,7 @@ namespace NodeCanvas.Tasks.Actions {
public void UpdateFloatValue(FloatValueGroup valueGroup, ref CameraSettingSingleValue<float> targetProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty.targetValue = valueGroup.value;
targetProperty.targetValue = valueGroup.value.value;
break;
case ValueChangeAction.ResetValue:
targetProperty.targetValue = targetProperty.originalValue;

View File

@@ -40,6 +40,7 @@ namespace Reset.Core {
public FloatValueGroup gravityMax = new (newLabel: "Gravity Max");
public FloatValueGroup gravityAcceleration = new (newLabel: "Gravity Acceleration Speed");
public FloatValueGroup gravityScale = new (newLabel: "Gravity Scale");
public FloatValueGroup settingsChangeSmoothing = new(newLabel: "Settings Change Smoothing");
// Rotation
[ParadoxNotion.Design.Header("Rotation")]
@@ -97,6 +98,7 @@ namespace Reset.Core {
UpdateFloatValue(gravityMax, ref agent.data.gravityMax, ref agent.defaultData.gravityMax);
UpdateFloatValue(gravityAcceleration, ref agent.data.gravityAcceleration, ref agent.defaultData.gravityAcceleration);
UpdateFloatValue(gravityScale, ref agent.data.gravityScale, ref agent.defaultData.gravityScale);
UpdateFloatValue(settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing, ref agent.data.settingsChangeSmoothing);
// Rotation
UpdateEnumValue(rotateFacing, ref agent.data.rotateFacing, ref agent.defaultData.rotateFacing);
@@ -222,7 +224,7 @@ namespace Reset.Core {
public void UpdateFloatValue(FloatValueGroup valueGroup, ref float targetProperty, ref float defaultProperty){
switch (valueGroup.changeValue) {
case ValueChangeAction.NewValue:
targetProperty = valueGroup.value;
targetProperty = valueGroup.value.value;
break;
case ValueChangeAction.ResetValue:
targetProperty = defaultProperty;

View File

@@ -1,4 +1,6 @@
using System;
using NodeCanvas.Editor;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEditor;
using UnityEngine;
@@ -97,13 +99,14 @@ namespace Reset.Core{
public struct FloatValueGroup{
public string label;
public float value;
// public float value;
public BBParameter<float> value;
public ValueChangeAction changeValue;
public FloatValueGroup(string newLabel){
label = newLabel;
value = 0f;
value = new BBParameter<float>().value = 0f;
changeValue = ValueChangeAction.NoChange;
}
}
@@ -123,7 +126,7 @@ namespace Reset.Core{
#if UNITY_EDITOR
public class BoolValueGroupDrawer : ObjectDrawer<BoolValueGroup> {
public override BoolValueGroup OnGUI(GUIContent content, BoolValueGroup _instance){
public override BoolValueGroup OnGUI(GUIContent _content, BoolValueGroup _instance){
// Remove label for floats
EditorGUIUtility.labelWidth = 50;
@@ -274,9 +277,11 @@ namespace Reset.Core{
// Create the x settings enum
_instance.changeValue = (ValueChangeAction)EditorGUILayout.EnumPopup("", instance.changeValue);
// Create the value/disabled information field
if (_instance.changeValue == ValueChangeAction.NewValue){
_instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
// _instance.value = EditorGUILayout.FloatField(_instance.value, floatOptions);
BBParameterEditor.ParameterField("", _instance.value);
} else {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField(_instance.changeValue == ValueChangeAction.NoChange ? "Unchanged" : "Reset", floatOptions);

View File

@@ -44,6 +44,7 @@ namespace Reset.Units{
public float gravityMax = 8f;
public float gravityAcceleration = 1f;
public float gravityScale = 1f;
public float settingsChangeSmoothing = 6f;
// Rotation
[ShowInInspector, SerializeReference]
@@ -72,6 +73,12 @@ namespace Reset.Units{
[ShowInInspector, ReadOnly] private Quaternion specifiedRotation;
[ShowInInspector, ReadOnly] private float outputRotationSpeed;
// Used by graph to gradually shift into new values rather than dump them. Even if they're smoothed values they need to be eased into
[ShowInInspector, ReadOnly] private float outputJumpDecay;
[ShowInInspector, ReadOnly] private float outputGravityAccel;
[ShowInInspector, ReadOnly] private float outputGravityScale;
[ShowInInspector, ReadOnly] private float settingsChangeRotationSpeed;
private float directionChangeDot;
private bool moveCallDisabledNextFrame;
@@ -204,7 +211,7 @@ namespace Reset.Units{
// Update the gravity, called every frame
private void UpdateCurrentGravity(){
// Accelerate gravity
// data.gravityPower += data.gravityAcceleration * Time.deltaTime;
data.gravityPower += outputGravityAccel * Time.deltaTime;
data.gravityPower = Mathf.Clamp(data.gravityPower, Mathf.NegativeInfinity, data.gravityMax);
// Apply a constant gravity if the player is grounded
@@ -263,7 +270,7 @@ namespace Reset.Units{
}
// Calculate rotation speed, as in how fast the fella rotates. This value has it's own smoothing to allow for gradual increasing/decreasing of the speed till it reaches the target
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed, data.rotationSmoothing * Time.deltaTime);
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed, settingsChangeRotationSpeed * Time.deltaTime);
// Set final rotation
transform.rotation = Quaternion.Slerp(transform.rotation, outputRotation, outputRotationSpeed * Time.deltaTime).Flatten(0, null, 0);
@@ -298,7 +305,7 @@ namespace Reset.Units{
// Add their related speeds
moveXZDir *= speed * Time.deltaTime;
moveYDir *= gravityScale * Time.deltaTime;
moveYDir *= outputGravityScale * Time.deltaTime;
addDir *= additionalSpeed * Time.deltaTime;
// Construct the direction and move
@@ -314,6 +321,14 @@ namespace Reset.Units{
void LateUpdate(){
UpdateGravityLate();
DecayAdditionalDirection();
SmoothingSettingsChanges();
}
private void SmoothingSettingsChanges(){
outputJumpDecay = Mathf.Lerp(outputJumpDecay, data.jumpPowerDecay, data.settingsChangeSmoothing * Time.deltaTime);
outputGravityAccel = Mathf.Lerp(outputGravityAccel, data.gravityAcceleration, data.settingsChangeSmoothing * Time.deltaTime);
outputGravityScale = Mathf.Lerp(outputGravityScale, data.gravityScale, data.settingsChangeSmoothing * Time.deltaTime);
settingsChangeRotationSpeed = Mathf.Lerp(settingsChangeRotationSpeed, data.rotationSpeed, data.settingsChangeSmoothing * Time.deltaTime);
}
void DecayAdditionalDirection(){
@@ -343,7 +358,7 @@ namespace Reset.Units{
private void UpdateGravityLate(){
// Decay jump power
data.jumpPower -= data.jumpPowerDecay * Time.deltaTime;
data.jumpPower -= outputJumpDecay * Time.deltaTime;
data.jumpPower = Mathf.Max(0f, data.jumpPower);
}
}