change: more alterations to the new movement and settingvalue system
This commit is contained in:
@@ -69,111 +69,77 @@ public class CameraSettingsProcessor : MonoBehaviour{
|
||||
axisCont = mainCamera.GetComponent<CinemachineInputAxisController>();
|
||||
|
||||
// Initialize camera settings values from current values
|
||||
data.mainFieldOfView.value = main.Lens.FieldOfView;
|
||||
data.mainFieldOfView.targetValue = main.Lens.FieldOfView;
|
||||
|
||||
data.orbitPositionDamping.value = orbit.TrackerSettings.PositionDamping;
|
||||
data.orbitTargetOffset.value = orbit.TargetOffset;
|
||||
data.orbitPositionDamping.targetValue = orbit.TrackerSettings.PositionDamping;
|
||||
data.orbitTargetOffset.targetValue = orbit.TargetOffset;
|
||||
|
||||
data.axisLookEnabledX.value = axisCont.Controllers[0].Enabled;
|
||||
data.axisLookEnabledY.value = axisCont.Controllers[1].Enabled;
|
||||
data.axisLookEnabledX.targetValue = axisCont.Controllers[0].Enabled;
|
||||
data.axisLookEnabledY.targetValue = axisCont.Controllers[1].Enabled;
|
||||
|
||||
data.axisLookGainX.value = axisCont.Controllers[0].Input.Gain;
|
||||
data.axisLookGainY.value = axisCont.Controllers[1].Input.Gain;
|
||||
data.axisLookGainX.targetValue = axisCont.Controllers[0].Input.Gain;
|
||||
data.axisLookGainY.targetValue = axisCont.Controllers[1].Input.Gain;
|
||||
|
||||
data.orbitFollowTopHeight.value = orbit.Orbits.Top.Height;
|
||||
data.orbitFollowTopRadius.value = orbit.Orbits.Top.Radius;
|
||||
data.orbitFollowCenterHeight.value = orbit.Orbits.Center.Height;
|
||||
data.orbitFollowCenterRadius.value = orbit.Orbits.Center.Radius;
|
||||
data.orbitFollowBottomHeight.value = orbit.Orbits.Bottom.Height;
|
||||
data.orbitFollowBottomRadius.value = orbit.Orbits.Bottom.Radius;
|
||||
data.orbitFollowTopHeight.targetValue = orbit.Orbits.Top.Height;
|
||||
data.orbitFollowTopRadius.targetValue = orbit.Orbits.Top.Radius;
|
||||
data.orbitFollowCenterHeight.targetValue = orbit.Orbits.Center.Height;
|
||||
data.orbitFollowCenterRadius.targetValue = orbit.Orbits.Center.Radius;
|
||||
data.orbitFollowBottomHeight.targetValue = orbit.Orbits.Bottom.Height;
|
||||
data.orbitFollowBottomRadius.targetValue = orbit.Orbits.Bottom.Radius;
|
||||
|
||||
data.rotationComposerScreenPos.value = rotComp.Composition.ScreenPosition;
|
||||
data.cameraOffsetOffset.value = offset.Offset;
|
||||
data.rotationComposerScreenPos.targetValue = rotComp.Composition.ScreenPosition;
|
||||
data.cameraOffsetOffset.targetValue = offset.Offset;
|
||||
|
||||
// And copy to the original
|
||||
original = (CameraSettingData)data.Clone();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
EaseToNewSmoothingValues();
|
||||
ProcessCameraValues();
|
||||
// EaseToNewSmoothingValues();
|
||||
// ProcessCameraValues();
|
||||
}
|
||||
|
||||
void EaseToNewSmoothingValues(){
|
||||
data.mainFieldOfView.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, data.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.mainFieldOfView.SmoothAndEase();
|
||||
|
||||
data.orbitPositionDamping.currentSmoothing = Mathf.MoveTowards(data.orbitPositionDamping.currentSmoothing, data.orbitPositionDamping.smoothing, easing.orbitPositionDamping.easing * Time.deltaTime);
|
||||
data.orbitTargetOffset.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitPositionDamping.SmoothAndEase();
|
||||
data.orbitTargetOffset.SmoothAndEase();
|
||||
|
||||
data.axisLookGainX.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.axisLookGainY.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.axisLookGainX.SmoothAndEase();
|
||||
data.axisLookGainY.SmoothAndEase();
|
||||
|
||||
data.orbitFollowTopHeight.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowTopRadius.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowCenterHeight.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowCenterRadius.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowBottomHeight.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowBottomRadius.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.orbitFollowTopHeight.SmoothAndEase();
|
||||
data.orbitFollowTopRadius.SmoothAndEase();
|
||||
data.orbitFollowCenterHeight.SmoothAndEase();
|
||||
data.orbitFollowCenterRadius.SmoothAndEase();
|
||||
data.orbitFollowBottomHeight.SmoothAndEase();
|
||||
data.orbitFollowBottomRadius.SmoothAndEase();
|
||||
|
||||
data.rotationComposerScreenPos.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.cameraOffsetOffset.currentSmoothing = Mathf.MoveTowards(data.mainFieldOfView.currentSmoothing, data.mainFieldOfView.smoothing, easing.mainFieldOfView.easing * Time.deltaTime);
|
||||
data.rotationComposerScreenPos.SmoothAndEase();
|
||||
data.cameraOffsetOffset.SmoothAndEase();
|
||||
}
|
||||
|
||||
void ProcessCameraValues(){
|
||||
main.Lens.FieldOfView = Mathf.SmoothDamp(main.Lens.FieldOfView,
|
||||
data.mainFieldOfView.value, ref data.mainFieldOfView.refVel,
|
||||
data.mainFieldOfView.smoothing);
|
||||
main.Lens.FieldOfView = data.mainFieldOfView.Value;
|
||||
|
||||
axisCont.Controllers[0].Enabled = data.axisLookEnabledX.value;
|
||||
|
||||
axisCont.Controllers[1].Enabled = data.axisLookEnabledY.value;
|
||||
axisCont.Controllers[0].Enabled = data.axisLookEnabledX.Value;
|
||||
axisCont.Controllers[1].Enabled = data.axisLookEnabledY.Value;
|
||||
|
||||
axisCont.Controllers[0].Input.Gain = Mathf.SmoothDamp(axisCont.Controllers[0].Input.Gain,
|
||||
data.axisLookGainX.value, ref data.axisLookGainX.refVel,
|
||||
data.axisLookGainX.smoothing);
|
||||
axisCont.Controllers[0].Input.Gain = data.axisLookGainX.Value;
|
||||
axisCont.Controllers[1].Input.Gain = data.axisLookGainY.Value;
|
||||
|
||||
orbit.TrackerSettings.PositionDamping = data.orbitPositionDamping.Value;
|
||||
orbit.TargetOffset = data.orbitTargetOffset.Value;
|
||||
|
||||
orbit.Orbits.Top.Height = data.orbitFollowTopHeight.Value;
|
||||
orbit.Orbits.Top.Radius = data.orbitFollowTopRadius.Value;
|
||||
orbit.Orbits.Center.Height = data.orbitFollowCenterHeight.Value;
|
||||
orbit.Orbits.Center.Radius = data.orbitFollowCenterRadius.Value;
|
||||
orbit.Orbits.Bottom.Height = data.orbitFollowBottomHeight.Value;
|
||||
orbit.Orbits.Bottom.Radius = data.orbitFollowBottomRadius.Value;
|
||||
|
||||
axisCont.Controllers[1].Input.Gain = Mathf.SmoothDamp(axisCont.Controllers[1].Input.Gain,
|
||||
data.axisLookGainY.value, ref data.axisLookGainY.refVel,
|
||||
data.axisLookGainY.smoothing);
|
||||
rotComp.Composition.ScreenPosition = data.rotationComposerScreenPos.Value;
|
||||
|
||||
orbit.TargetOffset = Vector3.SmoothDamp(orbit.TargetOffset,
|
||||
data.orbitTargetOffset.value, ref data.orbitTargetOffset.refVel,
|
||||
data.orbitTargetOffset.smoothing);
|
||||
|
||||
orbit.TrackerSettings.PositionDamping = Vector3.SmoothDamp(orbit.TrackerSettings.PositionDamping,
|
||||
data.orbitPositionDamping.value, ref data.orbitPositionDamping.refVel,
|
||||
data.orbitPositionDamping.smoothing);
|
||||
|
||||
orbit.Orbits.Top.Height = Mathf.SmoothDamp(orbit.Orbits.Top.Height,
|
||||
data.orbitFollowTopHeight.value, ref data.orbitFollowTopHeight.refVel,
|
||||
data.orbitFollowTopHeight.smoothing);
|
||||
|
||||
orbit.Orbits.Top.Radius = Mathf.SmoothDamp(orbit.Orbits.Top.Radius,
|
||||
data.orbitFollowTopRadius.value, ref data.orbitFollowTopRadius.refVel,
|
||||
data.orbitFollowTopRadius.smoothing);
|
||||
|
||||
orbit.Orbits.Center.Height = Mathf.SmoothDamp(orbit.Orbits.Center.Height,
|
||||
data.orbitFollowCenterHeight.value, ref data.orbitFollowCenterHeight.refVel,
|
||||
data.orbitFollowCenterHeight.smoothing);
|
||||
|
||||
orbit.Orbits.Center.Radius = Mathf.SmoothDamp(orbit.Orbits.Center.Radius,
|
||||
data.orbitFollowCenterRadius.value, ref data.orbitFollowCenterRadius.refVel,
|
||||
data.orbitFollowCenterRadius.smoothing);
|
||||
|
||||
orbit.Orbits.Bottom.Height = Mathf.SmoothDamp(orbit.Orbits.Bottom.Height,
|
||||
data.orbitFollowBottomHeight.value, ref data.orbitFollowBottomHeight.refVel,
|
||||
data.orbitFollowBottomHeight.smoothing);
|
||||
|
||||
orbit.Orbits.Bottom.Radius = Mathf.SmoothDamp(orbit.Orbits.Bottom.Radius,
|
||||
data.orbitFollowBottomRadius.value, ref data.orbitFollowBottomRadius.refVel,
|
||||
data.orbitFollowBottomRadius.smoothing);
|
||||
|
||||
rotComp.Composition.ScreenPosition = Vector2.SmoothDamp(rotComp.Composition.ScreenPosition,
|
||||
data.rotationComposerScreenPos.value, ref data.rotationComposerScreenPos.refVel,
|
||||
data.rotationComposerScreenPos.smoothing);
|
||||
|
||||
offset.Offset = Vector3.SmoothDamp(offset.Offset,
|
||||
data.cameraOffsetOffset.value, ref data.cameraOffsetOffset.refVel,
|
||||
data.cameraOffsetOffset.smoothing);
|
||||
offset.Offset = data.cameraOffsetOffset.Value;
|
||||
}
|
||||
}
|
||||
|
||||
10
Assets/Scripts/Player/PlayerFacingDirection.cs
Normal file
10
Assets/Scripts/Player/PlayerFacingDirection.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Reset.Units{
|
||||
public enum PlayerFacingDirection{
|
||||
TowardsTarget = 0,
|
||||
MatchForward,
|
||||
MatchCamera,
|
||||
Static,
|
||||
Momentum,
|
||||
SpecifiedDirection
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Player/PlayerFacingDirection.cs.meta
Normal file
3
Assets/Scripts/Player/PlayerFacingDirection.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81d909774c8e4b66be6e96fd13f9bff4
|
||||
timeCreated: 1758478092
|
||||
37
Assets/Scripts/Player/ResolvedMovement.cs
Normal file
37
Assets/Scripts/Player/ResolvedMovement.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class ResolvedMovement{
|
||||
public struct MoveDirection{
|
||||
private Transform owner;
|
||||
|
||||
private Vector2 _moveDir; // Always local
|
||||
|
||||
public Vector2 World{
|
||||
get => owner.TransformDirection(_moveDir);
|
||||
set{
|
||||
_moveDir = owner.InverseTransformDirection(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Local{
|
||||
get => _moveDir;
|
||||
set {
|
||||
_moveDir = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MoveDirection(Transform ownerTransform){
|
||||
owner = ownerTransform;
|
||||
_moveDir = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
[ShowInInspector] public MoveDirection moveDirection;
|
||||
public float moveSpeed;
|
||||
public Quaternion rotation;
|
||||
public float rotationSpeed;
|
||||
public float gravity;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Player/ResolvedMovement.cs.meta
Normal file
3
Assets/Scripts/Player/ResolvedMovement.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d663059052094322bff98f9ed2839fd9
|
||||
timeCreated: 1758478092
|
||||
@@ -1,24 +1,80 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public interface IResettableSettingValue{
|
||||
public abstract void SmoothAndEase();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct SettingValue<T>{
|
||||
public T value;
|
||||
public float smoothing; // Smoothing changes how fast value is changed.
|
||||
public float easing; // Easing changes how fast smoothing is changed, when given a new value.
|
||||
public struct SettingValue<T> : IResettableSettingValue{
|
||||
public T targetValue;
|
||||
public T currentValue;
|
||||
public T refVel;
|
||||
|
||||
public float currentSmoothing; // Actively eased and accessed value
|
||||
public float currentValue; // Actively smoothed and accessed value
|
||||
public float targetSmoothing; // Smoothing changes how fast the value is changed.
|
||||
public float targetEasing; // Easing changes how fast smoothing is changed, when given a new value.
|
||||
|
||||
public T refVel; // For use with SmoothDamp
|
||||
public T Value{
|
||||
get => currentValue;
|
||||
set => targetValue = value;
|
||||
}
|
||||
|
||||
private float currentSmoothing;
|
||||
|
||||
public T defaultValue;
|
||||
public float defaultSmoothing;
|
||||
public float defaultEasing;
|
||||
|
||||
private float refVelFloat; // For use with SmoothDamp
|
||||
private Vector3 refVelV3; // For use with SmoothDamp
|
||||
private Vector2 refVelV2; // For use with SmoothDamp
|
||||
|
||||
|
||||
public SettingValue(T initValue, float defaultEasing = 2f, float defaultSmoothing = 1f){
|
||||
value = initValue;
|
||||
|
||||
easing = defaultEasing;
|
||||
value = default;
|
||||
smoothing = defaultSmoothing;
|
||||
currentSmoothing = 0;
|
||||
currentValue = 0;
|
||||
targetValue = initValue;
|
||||
|
||||
this.defaultSmoothing = defaultSmoothing;
|
||||
this.defaultEasing = defaultEasing;
|
||||
|
||||
targetEasing = defaultEasing;
|
||||
targetSmoothing = defaultSmoothing;
|
||||
|
||||
currentSmoothing = targetSmoothing;
|
||||
currentValue = targetValue;
|
||||
|
||||
refVelFloat = 0;
|
||||
refVelV3 = default;
|
||||
refVelV2 = default;
|
||||
refVel = default;
|
||||
|
||||
defaultValue = initValue;
|
||||
}
|
||||
|
||||
public void SmoothAndEase(){
|
||||
Debug.Log("Worked!");
|
||||
return;
|
||||
|
||||
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * 1f * Time.deltaTime);
|
||||
|
||||
if (typeof(T) == typeof(float)) {
|
||||
currentValue = (T)(object)Mathf.SmoothDamp((float)(object)currentValue, (float)(object)targetValue, ref refVelFloat, currentSmoothing * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(Vector2)) {
|
||||
currentValue = (T)(object)Vector2.SmoothDamp((Vector2)(object)currentValue, (Vector2)(object)targetValue, ref refVelV2, currentSmoothing * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(Vector3)) {
|
||||
currentValue = (T)(object)Vector3.SmoothDamp((Vector3)(object)currentValue, (Vector3)(object)targetValue, ref refVelV3, currentSmoothing * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Quaternion)) {
|
||||
// I have... zero clue if this will work. There is no Vector4 or Quaternion SmoothDamp
|
||||
Vector3 v3value = Vector3.SmoothDamp((Vector4)(object)currentValue, (Vector4)(object)targetValue, ref refVelV3, currentSmoothing * Time.deltaTime);
|
||||
float v4value = Mathf.SmoothDamp(((Vector4)(object)currentValue).z, ((Vector4)(object)targetValue).z, ref refVelFloat, currentSmoothing * Time.deltaTime);
|
||||
|
||||
currentValue = (T)(object)new Vector4(v3value.x, v3value.y, v3value.z, v4value);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Assets/Scripts/Player/UnitMovementData.cs
Normal file
55
Assets/Scripts/Player/UnitMovementData.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ParadoxNotion.Design;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reset.Units{
|
||||
[Serializable]
|
||||
public class UnitMovementData : ICloneable{
|
||||
// Movement Direction
|
||||
public SettingValue<Vector2> moveSmoothing = new SettingValue<Vector2>(new Vector2(.5f, .5f));
|
||||
public SettingValue<float> acceleration = new SettingValue<float>(5f);
|
||||
public SettingValue<float> deacceleration = new SettingValue<float>(5f);
|
||||
|
||||
[SliderField(0,1)]
|
||||
public SettingValue<float> airDirectionDecay = new SettingValue<float>(1f); // TODO: Check default value
|
||||
|
||||
// Move Speed
|
||||
public SettingValue<float> softening = new SettingValue<float>(1f, defaultSmoothing: 1f);
|
||||
public SettingValue<float> moveSpeed = new SettingValue<float>(15f, defaultSmoothing: 10f);
|
||||
|
||||
// Jumping
|
||||
[ShowInInspector] public SettingValue<float> jumpPower = new SettingValue<float>(0f);
|
||||
public SettingValue<float> jumpPowerDecay = new SettingValue<float>(3f); // TODO: Check default value
|
||||
|
||||
// Gravity
|
||||
[ShowInInspector] public SettingValue<float> gravityPower = new SettingValue<float>(1f);
|
||||
public SettingValue<float> gravityMax = new SettingValue<float>(8f);
|
||||
public SettingValue<float> gravityAcceleration = new SettingValue<float>(1f);
|
||||
public SettingValue<float> gravityScale = new SettingValue<float>(1f);
|
||||
|
||||
// Rotation
|
||||
[ShowInInspector, SerializeReference] public Enum rotateFacing;
|
||||
public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
|
||||
public SettingValue<float> rotationInputBlending = new SettingValue<float>(.3f);
|
||||
|
||||
public object Clone(){
|
||||
return MemberwiseClone();
|
||||
}
|
||||
|
||||
public List<IResettableSettingValue> GetAllSettings(){
|
||||
var outputList = new List<IResettableSettingValue>();
|
||||
|
||||
IResettableSettingValue[] test = new[]{
|
||||
moveSmoothing as IResettableSettingValue,
|
||||
};
|
||||
|
||||
test[0].SmoothAndEase();
|
||||
|
||||
outputList.AddRange(test);
|
||||
|
||||
return outputList;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Player/UnitMovementData.cs.meta
Normal file
3
Assets/Scripts/Player/UnitMovementData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f5d86c96bcf450b888da32d1cf253e7
|
||||
timeCreated: 1758478092
|
||||
@@ -1,101 +1,12 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using ParadoxNotion.Design;
|
||||
using PlasticPipe.PlasticProtocol.Messages;
|
||||
using Reset.Core.Tools;
|
||||
using Sirenix.OdinInspector;
|
||||
|
||||
public enum PlayerFacingDirection{
|
||||
TowardsTarget = 0,
|
||||
MatchForward,
|
||||
MatchCamera,
|
||||
Static,
|
||||
Momentum,
|
||||
SpecifiedDirection
|
||||
}
|
||||
|
||||
namespace Reset.Units{
|
||||
// public interface IBuffSource{ - Unused good idea?
|
||||
// public Object sourceObject();
|
||||
// public
|
||||
// }
|
||||
|
||||
[Serializable]
|
||||
public class UnitMovementData : ICloneable{
|
||||
// Movement Direction
|
||||
public SettingValue<Vector2> moveSmoothing = new SettingValue<Vector2>(new Vector2(.5f, .5f));
|
||||
public SettingValue<float> acceleration = new SettingValue<float>(5f);
|
||||
public SettingValue<float> deaccerlation = new SettingValue<float>(5f);
|
||||
|
||||
[SliderField(0,1)]
|
||||
public SettingValue<float> airDirectionDecay = new SettingValue<float>(1f); // TODO: Check default value
|
||||
|
||||
// Move Speed
|
||||
public SettingValue<float> moveSpeed = new SettingValue<float>(15f, defaultSmoothing: 10f);
|
||||
|
||||
// Jumping
|
||||
[ShowInInspector] public SettingValue<float> jumpPower = new SettingValue<float>(0f);
|
||||
public SettingValue<float> jumpPowerDecay = new SettingValue<float>(3f); // TODO: Check default value
|
||||
|
||||
// Gravity
|
||||
[ShowInInspector] public SettingValue<float> gravityPower = new SettingValue<float>(1f);
|
||||
public SettingValue<float> gravityMax = new SettingValue<float>(8f);
|
||||
public SettingValue<float> gravityAcceleration = new SettingValue<float>(1f);
|
||||
public SettingValue<float> gravityScale = new SettingValue<float>(1f);
|
||||
|
||||
// Rotation
|
||||
[ShowInInspector, SerializeReference] public Enum rotateFacing;
|
||||
public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
|
||||
public SettingValue<float> rotationInputBlending = new SettingValue<float>(.3f);
|
||||
|
||||
public object Clone(){
|
||||
return MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
public class ResolvedMovement{
|
||||
[ShowInInspector] public UnitMovementHandler.MoveDirection moveDirection;
|
||||
public float moveSpeed;
|
||||
public Quaternion rotation;
|
||||
public float rotationSpeed;
|
||||
public float gravity;
|
||||
}
|
||||
|
||||
public class UnitMovementHandler : MonoBehaviour{
|
||||
public struct MoveDirection{
|
||||
private Transform owner;
|
||||
|
||||
private Vector2 _moveDir; // Always local
|
||||
|
||||
public Vector2 World{
|
||||
get => owner.TransformDirection(_moveDir);
|
||||
set{
|
||||
_moveDir = owner.InverseTransformDirection(value);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Local{
|
||||
get => _moveDir;
|
||||
set {
|
||||
_moveDir = value;
|
||||
}
|
||||
}
|
||||
|
||||
public MoveDirection(Transform ownerTransform){
|
||||
owner = ownerTransform;
|
||||
_moveDir = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
[ShowInInspector]
|
||||
public ResolvedMovement resolvedMovement;
|
||||
|
||||
// class MovementFloatModifier{
|
||||
// // IBuffSource source
|
||||
// public float value;
|
||||
// }
|
||||
|
||||
//
|
||||
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float outputSpeed;
|
||||
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float additionalSpeed;
|
||||
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] public Vector3 outputMoveDirection;
|
||||
@@ -104,7 +15,7 @@ namespace Reset.Units{
|
||||
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private Quaternion specifiedRotation;
|
||||
[FoldoutGroup("Final Values"), ShowInInspector, ReadOnly] private float outputRotationSpeed;
|
||||
|
||||
// Lerps
|
||||
// Smoothing Values
|
||||
private float directionChangeDotLerp;
|
||||
private Vector3 moveSmoothVelocityRef;
|
||||
private float gravitySmoothVelocityRef;
|
||||
@@ -116,12 +27,7 @@ namespace Reset.Units{
|
||||
|
||||
// Movement Data
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData data = new();
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData smoothing = new();
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData easing = new();
|
||||
|
||||
[HideInInspector] public UnitMovementData defaultData;
|
||||
[HideInInspector] public UnitMovementData defaultSmoothing;
|
||||
[HideInInspector] public UnitMovementData defaultEasing;
|
||||
|
||||
|
||||
void Awake(){
|
||||
controller = GetComponent<CharacterController>();
|
||||
@@ -130,12 +36,8 @@ namespace Reset.Units{
|
||||
}
|
||||
|
||||
void Start(){
|
||||
defaultData = (UnitMovementData)data.Clone();
|
||||
defaultSmoothing = (UnitMovementData)smoothing.Clone();
|
||||
defaultEasing = (UnitMovementData)easing.Clone();
|
||||
|
||||
resolvedMovement = new ResolvedMovement();
|
||||
resolvedMovement.moveDirection = new MoveDirection(transform);
|
||||
resolvedMovement.moveDirection = new ResolvedMovement.MoveDirection(transform);
|
||||
}
|
||||
|
||||
void Update(){
|
||||
@@ -188,7 +90,7 @@ namespace Reset.Units{
|
||||
return;
|
||||
}
|
||||
|
||||
outputSpeed = Mathf.Lerp(outputSpeed, Mathf.Max(data.moveSpeed.value, speed), priority);
|
||||
outputSpeed = Mathf.Lerp(outputSpeed, Mathf.Max(data.moveSpeed.Value, speed), priority);
|
||||
}
|
||||
|
||||
// Setting absolute to true will cause the current gravity to snap to the new gravity value.
|
||||
@@ -228,53 +130,47 @@ namespace Reset.Units{
|
||||
|
||||
// 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 (targetDirection.magnitude > currentDirection.magnitude) {
|
||||
if (controller.isGrounded){
|
||||
slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.acceleration.value * Time.deltaTime); // This used to be a slerp. If rotational movement broke this is why
|
||||
|
||||
// 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 {
|
||||
newDirection = Vector2.Lerp(currentDirection, targetDirection, data.acceleration.value * Time.deltaTime);
|
||||
}
|
||||
if (controller.isGrounded){
|
||||
slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.softening.Value * Time.deltaTime); // This used to be a slerp. If rotational movement broke this is why
|
||||
lerpedValue = Vector2.Lerp(currentDirection, targetDirection, data.softening.Value * Time.deltaTime);
|
||||
|
||||
newDirection = Vector2.Lerp(slerpedValue, lerpedValue, directionChangeDotLerp);
|
||||
} else {
|
||||
if (controller.isGrounded){
|
||||
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);
|
||||
|
||||
newDirection = Vector2.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp);
|
||||
} else {
|
||||
newDirection = Vector2.Lerp(currentDirection, targetDirection, data.deaccerlation.value * data.airDirectionDecay.value * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
newDirection = Vector2.Lerp(currentDirection, targetDirection, data.softening.Value * data.airDirectionDecay.Value * Time.deltaTime);
|
||||
}
|
||||
|
||||
// newDirection = Vector2.MoveTowards(currentDirection, targetDirection.Rotate(-Vector2.Angle(currentDirection, targetDirection)), 2f * Time.deltaTime);
|
||||
|
||||
// Commit move direction
|
||||
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 = 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????????
|
||||
float speed;
|
||||
|
||||
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, data.moveSpeed.value, data.moveSpeed.smoothing * Time.deltaTime);
|
||||
if (resolvedMovement.moveDirection.Local.magnitude < controls.rawMoveInput.magnitude) {
|
||||
speed = data.moveSpeed.Value * Time.deltaTime * data.acceleration.Value;
|
||||
} else {
|
||||
speed = data.moveSpeed.Value * Time.deltaTime * data.deacceleration.Value;
|
||||
}
|
||||
|
||||
resolvedMovement.moveSpeed = speed;
|
||||
|
||||
DebugOverlayDrawer.ChangeValue("Movement", "Resolved Speed", resolvedMovement.moveSpeed);
|
||||
}
|
||||
|
||||
// Update the gravity, called every frame
|
||||
private void UpdateCurrentGravity(){
|
||||
// Accelerate gravity
|
||||
if (!controller.isGrounded){
|
||||
resolvedMovement.gravity -= data.gravityAcceleration.value * Time.deltaTime;
|
||||
resolvedMovement.gravity -= data.gravityAcceleration.Value * Time.deltaTime;
|
||||
}
|
||||
|
||||
// resolvedMovement.gravity = Mathf.Clamp(resolvedMovement.gravity, Mathf.NegativeInfinity, data.gravityMax.value);
|
||||
@@ -285,7 +181,7 @@ namespace Reset.Units{
|
||||
}
|
||||
|
||||
// Create the final gravity value
|
||||
float gravityMoveDirection = data.jumpPower.value + (Physics.gravity.y * resolvedMovement.gravity);
|
||||
float gravityMoveDirection = data.jumpPower.Value + (Physics.gravity.y * resolvedMovement.gravity);
|
||||
// resolvedMovement.gravity = data.jumpPower.value + (Physics.gravity.y * data.gravityPower.currentValue);
|
||||
|
||||
// Commit gravity to move direction, ignoring XZ since those are done in UpdateMovementDirection
|
||||
@@ -332,11 +228,12 @@ namespace Reset.Units{
|
||||
|
||||
// Add the current input into the created rotation
|
||||
if (inputMovement.magnitude > .05){
|
||||
outputRotation = Quaternion.Lerp(outputRotation, Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement), data.rotationInputBlending.value);
|
||||
outputRotation = Quaternion.Lerp(outputRotation, Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement), data.rotationInputBlending.Value);
|
||||
}
|
||||
|
||||
// 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.value, data.rotationSpeed.smoothing * Time.deltaTime);
|
||||
|
||||
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed.Value, data.softening.Value * Time.deltaTime);
|
||||
|
||||
// Set final rotation
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, outputRotation, outputRotationSpeed * Time.deltaTime).Flatten(0, null, 0);
|
||||
@@ -344,7 +241,7 @@ namespace Reset.Units{
|
||||
|
||||
// Move with default settings
|
||||
public void DoMovement(){
|
||||
DoMovement(resolvedMovement.moveDirection.Local, resolvedMovement.moveSpeed, 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
|
||||
@@ -358,7 +255,7 @@ namespace Reset.Units{
|
||||
|
||||
// Add their related speeds
|
||||
moveXZDir *= speed * Time.deltaTime;
|
||||
moveYDir *= data.gravityScale.value * Time.deltaTime;
|
||||
moveYDir *= data.gravityScale.Value * Time.deltaTime;
|
||||
addDir *= additionalSpeed * Time.deltaTime;
|
||||
|
||||
// Construct the direction and move
|
||||
@@ -385,21 +282,30 @@ namespace Reset.Units{
|
||||
|
||||
// Decay the direction
|
||||
if (inputMovement.magnitude < currentNoY.magnitude) {
|
||||
additionalMoveDirection = Vector3.Slerp(additionalMoveDirection, Vector3.zero,data.acceleration.value * Time.deltaTime);
|
||||
additionalMoveDirection = Vector3.Slerp(additionalMoveDirection, Vector3.zero,data.acceleration.Value * Time.deltaTime);
|
||||
} else {
|
||||
// float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude);
|
||||
additionalMoveDirection = Vector3.Lerp(additionalMoveDirection, Vector3.zero, data.deaccerlation.value * Time.deltaTime);
|
||||
additionalMoveDirection = Vector3.Lerp(additionalMoveDirection, Vector3.zero, data.deacceleration.Value * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Decay the gravity
|
||||
additionalMoveDirection.y -= data.gravityPower.value;
|
||||
additionalMoveDirection.y -= data.gravityPower.Value;
|
||||
additionalMoveDirection.y = Mathf.Max(0f, additionalMoveDirection.y);
|
||||
}
|
||||
|
||||
private void UpdateGravityLate(){
|
||||
// Decay jump power
|
||||
data.jumpPower.value -= data.jumpPowerDecay.value * Time.deltaTime;
|
||||
data.jumpPower.value = Mathf.Max(0f, data.jumpPower.value);
|
||||
data.jumpPower.Value -= data.jumpPowerDecay.Value * Time.deltaTime;
|
||||
data.jumpPower.Value = Mathf.Max(0f, data.jumpPower.Value);
|
||||
}
|
||||
|
||||
[Button("Initialize Settings")]
|
||||
void InitAllSettings(){
|
||||
var newthing = data.GetAllSettings();
|
||||
}
|
||||
|
||||
void SmoothAllSettings(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user