68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using Intrepid.Structures;
|
|
using Intrepid.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Intrepid.Gameplay.Entities.Sentinel.StateMachine.States
|
|
{
|
|
public class SentinelStateRun : SentinelState
|
|
{
|
|
[GroupConfigurations, SerializeField] private AnimationClip run;
|
|
[GroupConfigurations, SerializeField, Range(0, 100)] private float speed = 10;
|
|
[GroupConfigurations, SerializeField, Range(0, 10)] private float animationSpeed = 1.2f;
|
|
|
|
private Vector2 Movement { get; set; }
|
|
|
|
public override SentinelStateType GetStateKey()
|
|
{
|
|
return SentinelStateType.Run;
|
|
}
|
|
|
|
protected override void Subscriptions()
|
|
{
|
|
}
|
|
|
|
protected override void RunOnEnter(ParameterStore parameterStore)
|
|
{
|
|
Brain.Entity.ModelAnimation.CrossFade(run, 0.1f, animationSpeed);
|
|
}
|
|
|
|
protected override void RunOnExit()
|
|
{
|
|
Brain.Entity.ChangeOrientation(Movement);
|
|
}
|
|
|
|
public override void RunOnUpdate()
|
|
{
|
|
Movement = Brain.Inputs.Movement();
|
|
Brain.Entity.ChangeOrientation(Movement);
|
|
if (CheckDash()) return;
|
|
if (CheckMovement()) return;
|
|
Brain.Entity.DesiredVelocity = Movement * speed;
|
|
}
|
|
|
|
private bool CheckDash()
|
|
{
|
|
if (Brain.Inputs.Dash())
|
|
{
|
|
Brain.ChangeState(SentinelStateType.Dash);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool CheckMovement()
|
|
{
|
|
switch (Movement.sqrMagnitude)
|
|
{
|
|
case <= SentinelConstants.Thresholds.Movement.DeadZoneSqrt:
|
|
Brain.ChangeState(SentinelStateType.Idle);
|
|
return true;
|
|
case < SentinelConstants.Thresholds.Movement.WalkZoneSqrt:
|
|
Brain.ChangeState(SentinelStateType.Walk);
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |