change: all movement separated into invidividual tasks, a lot of shuffling value groups and related stuff around
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using NUnit.Framework.Internal;
|
||||
using UnityEngine;
|
||||
using ParadoxNotion.Design;
|
||||
using PlasticPipe.PlasticProtocol.Messages;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine.Serialization;
|
||||
using Quaternion = UnityEngine.Quaternion;
|
||||
|
||||
public enum PlayerFacingDirection{
|
||||
TowardsTarget = 0,
|
||||
@@ -26,8 +24,7 @@ namespace Reset.Units{
|
||||
// Movement Direction
|
||||
public float accelerationSmoothing = 5f;
|
||||
public float deaccelerationSmoothing = 5f;
|
||||
// public AnimationCurve deaccelerationCurve; // Currently unused, may return
|
||||
|
||||
|
||||
[SliderField(0,1)]
|
||||
public float airDirectionDecay;
|
||||
|
||||
@@ -47,9 +44,8 @@ namespace Reset.Units{
|
||||
public float settingsChangeSmoothing = 6f;
|
||||
|
||||
// Rotation
|
||||
[ShowInInspector, SerializeReference]
|
||||
public Enum rotateFacing;
|
||||
[FormerlySerializedAs("rotationSpeedTarget")] public float rotationSpeed = 5f;
|
||||
[ShowInInspector, SerializeReference] public Enum rotateFacing;
|
||||
public float rotationSpeed = 5f;
|
||||
public float rotationSmoothing = 1f;
|
||||
public float rotationInputBlending = .3f;
|
||||
|
||||
@@ -57,8 +53,38 @@ namespace Reset.Units{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
public class ResolvedMovement{
|
||||
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(Local);
|
||||
set{
|
||||
moveDir = owner.InverseTransformDirection(value);
|
||||
Local = moveDir;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 Local{
|
||||
get => owner.InverseTransformDirection(World);
|
||||
set {
|
||||
moveDir = value;
|
||||
World = owner.TransformDirection(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// class MovementFloatModifier{
|
||||
// // IBuffSource source
|
||||
// public float value;
|
||||
@@ -79,25 +105,24 @@ namespace Reset.Units{
|
||||
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float smoothedGravityScale;
|
||||
[FoldoutGroup("Smoothed Values"), ShowInInspector, ReadOnly] private float settingsChangeRotationSpeed;
|
||||
|
||||
private float directionChangeDot;
|
||||
private bool moveCallDisabledNextFrame;
|
||||
|
||||
private bool movedThisFrame;
|
||||
// Lerps
|
||||
private float directionChangeDotLerp;
|
||||
private Vector3 moveSmoothVelocityRef;
|
||||
private float gravitySmoothVelocityRef;
|
||||
|
||||
// References
|
||||
private CharacterController controller;
|
||||
private PlayerControls controls;
|
||||
private LockOnManager lockOnManager;
|
||||
|
||||
private Vector3 moveSmooth;
|
||||
public float gravitySmooth;
|
||||
|
||||
private bool relativeToCamera;
|
||||
// Movement Data
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData data = new();
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData smoothing = new();
|
||||
[ShowInInspector, PropertyOrder(2)] public UnitMovementData easing = new();
|
||||
|
||||
[ShowInInspector, PropertyOrder(2)]
|
||||
public UnitMovementData data = new();
|
||||
|
||||
[HideInInspector]
|
||||
public UnitMovementData defaultData;
|
||||
[HideInInspector] public UnitMovementData defaultData;
|
||||
[HideInInspector] public UnitMovementData defaultSmoothing;
|
||||
[HideInInspector] public UnitMovementData defaultEasing;
|
||||
|
||||
void Awake(){
|
||||
controller = GetComponent<CharacterController>();
|
||||
@@ -105,15 +130,16 @@ namespace Reset.Units{
|
||||
lockOnManager = GetComponent<LockOnManager>();
|
||||
}
|
||||
|
||||
private void Start(){
|
||||
void Start(){
|
||||
defaultData = (UnitMovementData)data.Clone();
|
||||
defaultSmoothing = (UnitMovementData)smoothing.Clone();
|
||||
defaultEasing = (UnitMovementData)easing.Clone();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
UpdateCurrentDirection();
|
||||
UpdateCurrentGravity();
|
||||
UpdateCurrentSpeed();
|
||||
|
||||
UpdateCurrentRotation();
|
||||
|
||||
DoMovement();
|
||||
@@ -188,7 +214,7 @@ namespace Reset.Units{
|
||||
float switchedDirection = Vector3.Dot(inputMovement, outputMoveDirection);
|
||||
float switchedDirectionRemapped = Mathf.Lerp(0, 1, switchedDirection);
|
||||
|
||||
directionChangeDot = 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
|
||||
|
||||
// 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
|
||||
@@ -197,7 +223,7 @@ namespace Reset.Units{
|
||||
slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime);
|
||||
lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime);
|
||||
|
||||
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDot);
|
||||
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp);
|
||||
} else {
|
||||
currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.accelerationSmoothing * Time.deltaTime);
|
||||
}
|
||||
@@ -206,14 +232,14 @@ namespace Reset.Units{
|
||||
slerpedValue = Vector3.Slerp(currentNoY, targetNoY, data.deaccelerationSmoothing * Time.deltaTime);
|
||||
lerpedValue = Vector3.Lerp(currentNoY, targetNoY, data.deaccelerationSmoothing * Time.deltaTime);
|
||||
|
||||
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDot);
|
||||
currentNoY = Vector3.Lerp(lerpedValue, slerpedValue, directionChangeDotLerp);
|
||||
} else {
|
||||
currentNoY = Vector3.Lerp(currentNoY, targetNoY, data.deaccelerationSmoothing * data.airDirectionDecay * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Commit move direction
|
||||
outputMoveDirection = Vector3.SmoothDamp(outputMoveDirection, new Vector3(currentNoY.x, outputMoveDirection.y, currentNoY.z),ref moveSmooth , .5f *Time.deltaTime);
|
||||
outputMoveDirection = Vector3.SmoothDamp(outputMoveDirection, new Vector3(currentNoY.x, outputMoveDirection.y, currentNoY.z),ref moveSmoothVelocityRef , .5f *Time.deltaTime);
|
||||
}
|
||||
|
||||
// Update the speed, called every frame
|
||||
@@ -237,7 +263,7 @@ namespace Reset.Units{
|
||||
float gravityMoveDirection = data.jumpPower + (Physics.gravity.y * data.gravityPower);
|
||||
|
||||
// Commit gravity to move direction, ignoring XZ since those are done in UpdateMovementDirection
|
||||
outputMoveDirection.y = Mathf.SmoothDamp(outputMoveDirection.y, gravityMoveDirection, ref gravitySmooth, .1f * Time.deltaTime);
|
||||
outputMoveDirection.y = Mathf.SmoothDamp(outputMoveDirection.y, gravityMoveDirection, ref gravitySmoothVelocityRef, .1f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Update the rotation, called every frame
|
||||
@@ -294,10 +320,6 @@ namespace Reset.Units{
|
||||
public void DoMovement(){
|
||||
DoMovement(outputMoveDirection, outputSpeed, data.gravityScale);
|
||||
}
|
||||
|
||||
public void DisableNextMoveCall(){
|
||||
moveCallDisabledNextFrame = true;
|
||||
}
|
||||
|
||||
// Custom move from input
|
||||
public void DoMovement(Vector3 moveDir, float speed, float gravityScale){
|
||||
|
||||
Reference in New Issue
Block a user