diff --git a/MovementController.cs b/MovementController.cs index 672a140..f2c4cae 100644 --- a/MovementController.cs +++ b/MovementController.cs @@ -31,6 +31,8 @@ namespace Syntriax.Modules.Movement } } + private bool areBothToggleStatesToggled => ToggleState.IsToggledNullChecked() && toggleStateOnGameObject.IsToggledNullChecked(); + public List Movements { get; protected set; } = new List(32); public IToggleState ToggleState { get; protected set; } = new ToggleStateMember(true); @@ -44,11 +46,14 @@ namespace Syntriax.Modules.Movement RecacheMovements(); toggleStateOnGameObject = GetComponent(); + + toggleStateOnGameObject.OnToggleStateChanged += (_) => InvokeOnMoveAction(); + ToggleState.OnToggleStateChanged += (_) => InvokeOnMoveAction(); } protected virtual void FixedUpdate() { - if (!ToggleState.IsToggledNullChecked() || !toggleStateOnGameObject.IsToggledNullChecked()) + if (!areBothToggleStatesToggled) return; ActiveMovement?.ApplyMovement(); @@ -79,10 +84,21 @@ namespace Syntriax.Modules.Movement } } + private Vector3 lastMove = Vector3.zero; public void Move(float x = 0, float y = 0, float z = 0) { ActiveMovement?.Move(x, y, z); - OnMoveCalled?.Invoke(x, y, z); + (lastMove.x, lastMove.y, lastMove.z) = (x, y, z); + + InvokeOnMoveAction(); + } + + private void InvokeOnMoveAction() + { + if (!areBothToggleStatesToggled) + return; + + OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z); } } }