change: finished and cleaned all settings changes, code commented, smoothing and easing are now exponential

This commit is contained in:
Chris
2025-09-26 14:03:11 -04:00
parent bd2903a0b2
commit 4569cea664
20 changed files with 676 additions and 399 deletions

View File

@@ -1,39 +1,37 @@
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
public struct CameraSettingData : ICloneable{
public SettingValue<float> mainFieldOfView;
[Serializable]
public class CameraSettingData{
[Title("Field of View"), HideLabel, InlineProperty] public SettingValue<float> mainFieldOfView = new SettingValue<float>(0f);
public SettingValue<Vector3> orbitPositionDamping;
public SettingValue<Vector3> orbitTargetOffset;
[Title("Orbit Position Damping"), HideLabel, InlineProperty] public SettingValue<Vector3> orbitPositionDamping = new SettingValue<Vector3>(Vector3.zero);
[Title("Orbit Target Offset"), HideLabel, InlineProperty] public SettingValue<Vector3> orbitTargetOffset= new SettingValue<Vector3>(Vector3.zero);
public SettingValue<bool> axisLookEnabledX;
public SettingValue<bool> axisLookEnabledY;
[Title("X Axis Look Enabled"), HideLabel, InlineProperty] public SettingValue<bool> axisLookEnabledX = new SettingValue<bool>(true);
[Title("Y Axis Look Enabled"), HideLabel, InlineProperty] public SettingValue<bool> axisLookEnabledY = new SettingValue<bool>(true);
public SettingValue<float> axisLookGainX;
public SettingValue<float> axisLookGainY;
[Title("X Axis Look Gain"), HideLabel, InlineProperty] public SettingValue<float> axisLookGainX = new SettingValue<float>(0f);
[Title("Y Axis Look Gain"), HideLabel, InlineProperty] public SettingValue<float> axisLookGainY = new SettingValue<float>(0f);
public SettingValue<float> orbitFollowTopHeight;
public SettingValue<float> orbitFollowTopRadius;
public SettingValue<float> orbitFollowCenterHeight;
public SettingValue<float> orbitFollowCenterRadius;
public SettingValue<float> orbitFollowBottomHeight;
public SettingValue<float> orbitFollowBottomRadius;
[Title("Orbit Follow Top Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowTopHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Top Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowTopRadius = new SettingValue<float>(0f);
[Title("Orbit Follow Center Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowCenterHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Center Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowCenterRadius = new SettingValue<float>(0f);
[Title("Orbit Follow Bottom Height"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowBottomHeight = new SettingValue<float>(0f);
[Title("Orbit Follow Bottom Radius"), HideLabel, InlineProperty] public SettingValue<float> orbitFollowBottomRadius = new SettingValue<float>(0f);
public SettingValue<Vector2> rotationComposerScreenPos;
public SettingValue<Vector2> rotationComposerScreenPos= new SettingValue<Vector2>(Vector2.zero);
public SettingValue<Vector3> cameraOffsetOffset;
public object Clone(){
return MemberwiseClone();
}
public SettingValue<Vector3> cameraOffsetOffset= new SettingValue<Vector3>(Vector3.zero);
public List<IResettableSettingValue> GetAllSettings(){
var outputList = new List<IResettableSettingValue>();
IResettableSettingValue[] settings = new[]{
mainFieldOfView as IResettableSettingValue,
IResettableSettingValue[] settings = {
mainFieldOfView,
orbitPositionDamping,
orbitTargetOffset,
axisLookEnabledX,

View File

@@ -1,3 +1,4 @@
using System;
using Reset.Core;
using Sirenix.OdinInspector;
using Unity.Cinemachine;
@@ -6,14 +7,8 @@ using UnityEngine;
public class CameraSettingsProcessor : MonoBehaviour{
public static CameraSettingsProcessor Instance{ get; private set; }
[HideInInspector] public static CameraSettingData data;
[HideInInspector] public static CameraSettingData original;
[ShowInInspector] public static CameraSettingData smoothing;
[ShowInInspector] public static CameraSettingData easing;
[HideInInspector] public static CameraSettingData currentSmoothing;
[HideInInspector] public static CameraSettingData currentValue;
[ShowInInspector, FoldoutGroup("Camera Data", expanded: true), InlineProperty, HideLabel]
public CameraSettingData data;
public static GameObject mainCamera;
@@ -38,59 +33,32 @@ public class CameraSettingsProcessor : MonoBehaviour{
rotComp = mainCamera.GetComponent<CinemachineRotationComposer>();
offset = mainCamera.GetComponent<CinemachineCameraOffset>();
axisCont = mainCamera.GetComponent<CinemachineInputAxisController>();
// Quick check for a camera settings
if (data == null) {
Debug.LogWarning("No Camera Settings Data was found on processing. One will be created. Is this intentional? This will have strong effects on camera movement");
data = new CameraSettingData();
}
// Initialize camera settings values from current values
data.mainFieldOfView.targetValue = main.Lens.FieldOfView;
data.orbitPositionDamping.targetValue = orbit.TrackerSettings.PositionDamping;
data.orbitTargetOffset.targetValue = orbit.TargetOffset;
data.axisLookEnabledX.targetValue = axisCont.Controllers[0].Enabled;
data.axisLookEnabledY.targetValue = axisCont.Controllers[1].Enabled;
data.axisLookGainX.targetValue = axisCont.Controllers[0].Input.Gain;
data.axisLookGainY.targetValue = axisCont.Controllers[1].Input.Gain;
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.targetValue = rotComp.Composition.ScreenPosition;
data.cameraOffsetOffset.targetValue = offset.Offset;
// And copy to the original
original = (CameraSettingData)data.Clone();
InitializeAllSettings();
}
void Update(){
// EaseToNewSmoothingValues();
// ProcessCameraValues();
SmoothCameraSettings();
ApplyCameraSettings();
}
void EaseToNewSmoothingValues(){
data.mainFieldOfView.SmoothAndEase();
data.orbitPositionDamping.SmoothAndEase();
data.orbitTargetOffset.SmoothAndEase();
data.axisLookGainX.SmoothAndEase();
data.axisLookGainY.SmoothAndEase();
data.orbitFollowTopHeight.SmoothAndEase();
data.orbitFollowTopRadius.SmoothAndEase();
data.orbitFollowCenterHeight.SmoothAndEase();
data.orbitFollowCenterRadius.SmoothAndEase();
data.orbitFollowBottomHeight.SmoothAndEase();
data.orbitFollowBottomRadius.SmoothAndEase();
void SmoothCameraSettings(){
var settings = data.GetAllSettings();
data.rotationComposerScreenPos.SmoothAndEase();
data.cameraOffsetOffset.SmoothAndEase();
for (int i = 0; i < settings.Count; i++) {
settings[i].SmoothAndEase();
}
}
void ProcessCameraValues(){
// Responsible for actively applying the settings to the Cinemachine components
void ApplyCameraSettings(){
main.Lens.FieldOfView = data.mainFieldOfView.Value;
axisCont.Controllers[0].Enabled = data.axisLookEnabledX.Value;
@@ -113,9 +81,30 @@ public class CameraSettingsProcessor : MonoBehaviour{
offset.Offset = data.cameraOffsetOffset.Value;
}
[Button]
void InitializeAllSettings(){
data.mainFieldOfView.targetValue = main.Lens.FieldOfView;
data.orbitPositionDamping.targetValue = orbit.TrackerSettings.PositionDamping;
data.orbitTargetOffset.targetValue = orbit.TargetOffset;
data.axisLookEnabledX.targetValue = axisCont.Controllers[0].Enabled;
data.axisLookEnabledY.targetValue = axisCont.Controllers[1].Enabled;
data.axisLookGainX.targetValue = axisCont.Controllers[0].Input.Gain;
data.axisLookGainY.targetValue = axisCont.Controllers[1].Input.Gain;
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.targetValue = rotComp.Composition.ScreenPosition;
data.cameraOffsetOffset.targetValue = offset.Offset;
var allSettings = data.GetAllSettings();
for (int i = 0; i < allSettings.Count; i++) {
allSettings[i].Initialize();

View File

@@ -1,7 +1,7 @@
namespace Reset.Units{
public enum PlayerFacingDirection{
TowardsTarget = 0,
MatchForward,
MatchInput,
MatchCamera,
Static,
Momentum,

View File

@@ -7,14 +7,14 @@ namespace Reset.Units{
public struct MoveDirection{
private Transform owner;
// Both are in world space, and translated to local
private Vector2 _moveRaw;
private Vector2 _moveDir; // Always world??
private Vector2 _moveDir;
[ShowInInspector]
public Vector2 World{
get{
DebugOverlayDrawer.ChangeValue("Movement", "_moveDir", _moveDir);
// return owner.TransformDirection(_moveDir.ToVector3()).ToVector2();
return _moveDir;
}
set{
@@ -23,14 +23,9 @@ namespace Reset.Units{
}
[ShowInInspector]
public Vector2 Local{
get => owner.InverseTransformDirection(_moveDir.ToVector3()).ToVector2();
private set {
// _moveDir = value;
}
}
public Vector2 Local => owner.InverseTransformDirection(_moveDir.ToVector3()).ToVector2();
[ShowInInspector, PropertySpace(5)]
public Vector2 RawWorld{
get{
DebugOverlayDrawer.ChangeValue("Movement", "_moveRaw", _moveRaw);
@@ -42,11 +37,9 @@ namespace Reset.Units{
}
}
public Vector2 RawLocal{
get => owner.InverseTransformDirection(_moveRaw.ToVector3()).ToVector2();
}
[ShowInInspector]
public Vector2 RawLocal => owner.InverseTransformDirection(_moveRaw.ToVector3()).ToVector2();
public MoveDirection(Transform ownerTransform){
owner = ownerTransform;
_moveDir = Vector2.zero;
@@ -54,7 +47,7 @@ namespace Reset.Units{
}
}
[ShowInInspector] public MoveDirection moveDirection;
[ShowInInspector, InlineProperty, BoxGroup("Direction"), HideLabel] public MoveDirection moveDirection;
public float moveSpeed;
public Quaternion rotation;
public float rotationSpeed;

View File

@@ -25,7 +25,7 @@ public class SettingValue<T> : IResettableSettingValue{
set => targetValue = value;
}
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Current"), ShowIf("@IsSmoothable()")]
private float currentSmoothing;
public float currentSmoothing;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Value"), BoxGroup("Settings/Value/Value"), LabelText("Default")]
public T defaultValue;
[HorizontalGroup("Settings"), VerticalGroup("Settings/Smoothing"), BoxGroup("Settings/Smoothing/Smoothing"), LabelText("Default"), ShowIf("@IsSmoothable()")]
@@ -75,31 +75,33 @@ public class SettingValue<T> : IResettableSettingValue{
Debug.LogWarning($"A SettingValue ({this}) wasn't verified before being smoothed and eased. What's up with that?");
}
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * 1f * Time.deltaTime);
currentSmoothing = Mathf.MoveTowards(currentSmoothing, targetSmoothing, targetEasing * targetEasing * Time.deltaTime);
if (typeof(T) == typeof(float)) {
currentValue = (T)(object)Mathf.SmoothDamp((float)(object)currentValue, (float)(object)targetValue, ref refVelFloat, currentSmoothing * Time.deltaTime);
currentValue = (T)(object)Mathf.SmoothDamp((float)(object)currentValue, (float)(object)targetValue, ref refVelFloat, currentSmoothing * currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector2)) {
currentValue = (T)(object)Vector2.SmoothDamp((Vector2)(object)currentValue, (Vector2)(object)targetValue, ref refVelV2, currentSmoothing * Time.deltaTime);
currentValue = (T)(object)Vector2.SmoothDamp((Vector2)(object)currentValue, (Vector2)(object)targetValue, ref refVelV2, currentSmoothing * currentSmoothing * Time.deltaTime);
}
if (typeof(T) == typeof(Vector3)) {
currentValue = (T)(object)Vector3.SmoothDamp((Vector3)(object)currentValue, (Vector3)(object)targetValue, ref refVelV3, currentSmoothing * Time.deltaTime);
currentValue = (T)(object)Vector3.SmoothDamp((Vector3)(object)currentValue, (Vector3)(object)targetValue, ref refVelV3, currentSmoothing * 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);
Vector3 v3value = Vector3.SmoothDamp((Vector4)(object)currentValue, (Vector4)(object)targetValue, ref refVelV3, currentSmoothing * currentSmoothing * Time.deltaTime);
float v4value = Mathf.SmoothDamp(((Vector4)(object)currentValue).z, ((Vector4)(object)targetValue).z, ref refVelFloat, currentSmoothing * currentSmoothing * Time.deltaTime);
currentValue = (T)(object)new Vector4(v3value.x, v3value.y, v3value.z, v4value);
}
}
public void Initialize(){
currentValue = targetValue;
Debug.Log(Value);
defaultValue = targetValue;
defaultSmoothing = targetSmoothing;
defaultEasing = targetEasing;
}
}

View File

@@ -6,17 +6,18 @@ using UnityEngine;
namespace Reset.Units{
[Serializable]
public class UnitMovementData : ICloneable{
public class UnitMovementData{
// Movement Direction
[Title("Move Smoothing"), HideLabel, InlineProperty] public SettingValue<Vector2> moveSmoothing = new SettingValue<Vector2>(new Vector2(.5f, .5f));
[Title("Acceleration"), HideLabel, InlineProperty] public SettingValue<float> acceleration = new SettingValue<float>(5f);
[Title("Deacceleration"), HideLabel, InlineProperty] public SettingValue<float> deacceleration = new SettingValue<float>(5f);
[Title("Direction Changing Softeness"), HideLabel, InlineProperty] public SettingValue<float> directionChangingSoftness = new SettingValue<float>(1f, defaultSmoothing: 1f);
[Title("Direction Spinning Hardness"), HideLabel, InlineProperty] public SettingValue<float> directionSpinningHardness = new SettingValue<float>(3f, defaultSmoothing: 1f);
[Title("Directoon Spinning Speed"), HideLabel, InlineProperty] public SettingValue<float> directionSpinningSpeed= new SettingValue<float>(3f, defaultSmoothing: 1f);
[SliderField(0,1)]
[Title("Air Direction Decay"), HideLabel, InlineProperty] public SettingValue<float> airDirectionDecay = new SettingValue<float>(1f); // TODO: Check default value
// Move Speed
[Title("Softening"), HideLabel, InlineProperty] public SettingValue<float> softening = new SettingValue<float>(1f, defaultSmoothing: 1f);
[Title("Acceleration"), HideLabel, InlineProperty] public SettingValue<float> acceleration = new SettingValue<float>(5f);
[Title("Deacceleration"), HideLabel, InlineProperty] public SettingValue<float> deacceleration = new SettingValue<float>(5f);
[Title("Move Speed"), HideLabel, InlineProperty] public SettingValue<float> moveSpeed = new SettingValue<float>(15f, defaultSmoothing: 10f);
// Jumping
@@ -30,33 +31,27 @@ namespace Reset.Units{
[Title("Gravity Scale"), HideLabel, InlineProperty] public SettingValue<float> gravityScale = new SettingValue<float>(1f);
// Rotation
[Title("Rotate Facing"), HideLabel, InlineProperty] public SettingValue<PlayerFacingDirection> rotateFacing = new SettingValue<PlayerFacingDirection>(initValue: PlayerFacingDirection.Momentum);
[Title("Rotate Facing"), HideLabel, InlineProperty] public SettingValue<PlayerFacingDirection> facingDirection = new SettingValue<PlayerFacingDirection>(initValue: PlayerFacingDirection.Momentum);
[Title("Rotation Speed"), HideLabel, InlineProperty] public SettingValue<float> rotationSpeed = new SettingValue<float>(5f);
[Title("Rotation Input Blending"), HideLabel, InlineProperty] public SettingValue<float> rotationInputBlending = new SettingValue<float>(.3f);
public object Clone(){
return MemberwiseClone();
}
public List<IResettableSettingValue> GetAllSettings(){
var outputList = new List<IResettableSettingValue>();
IResettableSettingValue[] settings = new[]{
moveSmoothing as IResettableSettingValue,
IResettableSettingValue[] settings = {
directionChangingSoftness,
directionSpinningHardness,
directionSpinningSpeed,
acceleration,
deacceleration,
airDirectionDecay,
softening,
moveSpeed,
// jumpPower,
// jumpPowerDecay,
gravityPower,
gravityMax,
gravityAcceleration,
gravityScale,
rotateFacing,
facingDirection,
rotationSpeed,
rotationInputBlending,
};
outputList.AddRange(settings);

View File

@@ -8,13 +8,8 @@ namespace Reset.Units{
[ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)]
public ResolvedMovement resolvedMovement;
[HideInInspector] public Vector3 outputMoveDirection;
[HideInInspector] public Vector3 additionalMoveDirection;
// SmoothDamp Velocities
private Quaternion refVelocityRotationSpeed;
private float refVelocityAcceleration;
private float refVelocityDeacceleration;
private Vector2 refVelocityDirectionChangingHardness;
// Smoothing Values
private float directionChangeDotLerp;
@@ -29,6 +24,9 @@ namespace Reset.Units{
// Movement Data
[ShowInInspector, PropertyOrder(2), FoldoutGroup("Movement Data", expanded: true), InlineProperty, HideLabel] public UnitMovementData data = new();
// Other
private Quaternion specifiedRotation; // Used for locking a specific direction
void Awake(){
controller = GetComponent<CharacterController>();
controls = GetComponent<PlayerControls>();
@@ -45,13 +43,14 @@ namespace Reset.Units{
void Update(){
SmoothAllSettings();
UpdateCurrentDirection();
UpdateCurrentGravity();
UpdateCurrentSpeed();
UpdateCurrentRotation();
DoMovement();
// Apply movement
DoMovement(resolvedMovement.moveDirection.World, resolvedMovement.gravity, resolvedMovement.moveSpeed, data.gravityScale.Value);
DebugOverlayDrawer.ChangeValue("Movement", "Move Direction (Local)", resolvedMovement.moveDirection.Local);
DebugOverlayDrawer.ChangeValue("Movement", "Move Direction (World)", resolvedMovement.moveDirection.World);
@@ -62,6 +61,7 @@ namespace Reset.Units{
// Get input value
Vector2 targetDirection = new Vector2(controls.rawMoveInput.x, controls.rawMoveInput.y);
// Rotate input by camera rotation (instead of rotating the output direction by camera rotation)
targetDirection = (Camera.main.transform.rotation * targetDirection.ToVector3()).ToVector2();
// Deadzone
@@ -69,7 +69,7 @@ namespace Reset.Units{
targetDirection = Vector2.zero;
}
// Set Raw Direciton
// Set Raw Direction (this is used by the camera later)
resolvedMovement.moveDirection.RawWorld = targetDirection;
// Get current direction
@@ -79,7 +79,7 @@ namespace Reset.Units{
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
directionChangeDotLerp = Mathf.Lerp(switchedDirection, switchedDirectionRemapped, data.directionSpinningHardness.Value * Time.deltaTime);
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
@@ -89,12 +89,12 @@ namespace Reset.Units{
Vector2 newDirection;
if (controller.isGrounded){
slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.softening.Value * Time.deltaTime);
lerpedValue = Vector2.Lerp(currentDirection, targetDirection, data.softening.Value * Time.deltaTime);
slerpedValue = Vector3.Slerp(currentDirection, targetDirection, data.directionSpinningSpeed.Value * Time.deltaTime);
lerpedValue = Vector2.SmoothDamp(currentDirection, targetDirection, ref refVelocityDirectionChangingHardness, data.directionChangingSoftness.Value * Time.deltaTime);
newDirection = Vector2.Lerp(slerpedValue, lerpedValue, directionChangeDotLerp);
} else {
newDirection = Vector2.Lerp(currentDirection, targetDirection, data.softening.Value * data.airDirectionDecay.Value * Time.deltaTime);
newDirection = Vector2.SmoothDamp(currentDirection, targetDirection, ref refVelocityDirectionChangingHardness, data.directionChangingSoftness.Value * data.airDirectionDecay.Value * Time.deltaTime);
}
// Commit the new direction
@@ -119,6 +119,7 @@ namespace Reset.Units{
}
// Update the gravity, called every frame
// NOTE: most gravity interactions, like when grounded or not, is now handled by the state machine
private void UpdateCurrentGravity(){
// Accelerate gravity
if (!controller.isGrounded){
@@ -136,10 +137,16 @@ namespace Reset.Units{
Quaternion targetRotation = Quaternion.identity;
// Switch the desired rotation based on current movement setting
switch (data.rotateFacing.Value) { // TODO: Check that this isn't broken
switch (data.facingDirection.Value) {
// Just look at target
case PlayerFacingDirection.TowardsTarget:
// Look directly at the target
if (lockOnManager.mainTarget == null) {
Debug.LogError("Trying to rotate towards a target but there is no target. Not setting a rotation");
targetRotation = transform.rotation;
break;
}
targetRotation = Quaternion.LookRotation(transform.position.DirectionTo(lockOnManager.mainTarget.gameObject.transform.position));
break;
case PlayerFacingDirection.Momentum:
@@ -148,8 +155,8 @@ namespace Reset.Units{
targetRotation = Quaternion.LookRotation(resolvedMovement.moveDirection.RawWorld.ToVector3(), Vector3.up);
}
break;
case PlayerFacingDirection.MatchForward:
// Look towards the input direction....why??? I guess cause move direction is PlayerFacingDirection.Momentum.
case PlayerFacingDirection.MatchInput:
// Look towards the input direction- similar to Momentum but snappier
if (controls.rawMoveInput.magnitude < 0.05f) { break; }
targetRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
@@ -160,7 +167,7 @@ namespace Reset.Units{
break;
case PlayerFacingDirection.Static:
// Don't change
targetRotation = transform.rotation;
targetRotation = resolvedMovement.rotation;
break;
}
@@ -168,27 +175,21 @@ namespace Reset.Units{
// Add the current input into the created rotation
if (inputMovement.magnitude > .05) {
// Quaternion inputRot = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement);
// resolvedMovement.rotation = Quaternion.RotateTowards(resolvedMovement.rotation, targetRotation, 10f);
resolvedMovement.rotation = targetRotation;
} else if (data.facingDirection.Value == PlayerFacingDirection.MatchCamera) {
resolvedMovement.rotation = targetRotation;
}
// Set final rotation
// Apply rotation to the character
transform.rotation = Quaternion.Slerp(transform.rotation, resolvedMovement.rotation, data.rotationSpeed.Value * Time.deltaTime).Flatten(0, null, 0);
}
// Move with default settings
public void DoMovement(){
DoMovement(resolvedMovement.moveDirection.World, resolvedMovement.moveSpeed, data.gravityScale.Value); // TODO: Gets multiplied a second time in DoMovement by gravity scale????
}
// Custom move from input
public void DoMovement(Vector2 moveDir, float speed, float gravityScale){
// Debug.Log($"moveDir: {moveDir}, agent velocity: {transform.InverseTransformDirection(controller.velocity.normalized)}");
// Custom move from input
private void DoMovement(Vector2 moveDir, float gravDir, float speed, float gravityScale){
// Seperate the different move directions. Additonal becomes it's own because it needs to be added independently of the other two
Vector2 moveXZDir = moveDir;
float moveYDir = resolvedMovement.gravity;
float moveYDir = gravDir;
// Add their related speeds
moveXZDir *= speed * Time.deltaTime;
@@ -209,7 +210,7 @@ namespace Reset.Units{
}
}
public void SetNewDirection(Vector2 value, float relativity, bool absolute){ // new
public void SetNewDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
if (absolute){
resolvedMovement.moveDirection.World = Vector2.Lerp(resolvedMovement.moveDirection.World, value, relativity);
} else {
@@ -217,7 +218,7 @@ namespace Reset.Units{
}
}
public void SetNewRawDirection(Vector2 value, float relativity, bool absolute){ // new
public void SetNewRawDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
if (absolute){
resolvedMovement.moveDirection.RawWorld = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, value, relativity);
} else {
@@ -225,7 +226,7 @@ namespace Reset.Units{
}
}
public void SetNewSpeed(float value, float relativity, bool absolute){ // new
public void SetNewSpeed(float value, float relativity, bool absolute, float relativeTo = Mathf.Infinity){ // new
if (absolute){
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, value, relativity);
} else {
@@ -233,7 +234,7 @@ namespace Reset.Units{
}
}
public void SetNewRotation(Quaternion value, float relativity, bool absolute){ // new
public void SetNewRotation(Quaternion value, float relativity, bool absolute, Quaternion relativeTo = default){ // new
if (absolute){
resolvedMovement.rotation = Quaternion.Lerp(resolvedMovement.rotation, value, relativity);
} else {
@@ -241,6 +242,10 @@ namespace Reset.Units{
}
}
public void SetSpecifiedRotation(Quaternion inputRotation){
specifiedRotation = inputRotation;
}
[Button("Initialize Settings", ButtonHeight = 30), PropertySpace(10,5 )]
void InitAllSettings(){
var settingsList = data.GetAllSettings();
@@ -274,14 +279,11 @@ namespace Reset.Units{
public void SetNewGravity(float value){
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void SetSpecifiedRotation(Quaternion inputRotation){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
public void OverwriteDirectionFromInput(Vector2 value, float priority, float speed = Mathf.Infinity){ // Old
Debug.LogError("Using an old movement command! Switch to one of the new alternatives!");
}
}
}