chore: initial commit
This commit is contained in:
53
Assets/Scripts/Player/States/FallState.cs
Normal file
53
Assets/Scripts/Player/States/FallState.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Player.States
|
||||
{
|
||||
/// <summary>下落状态。着地后转为 Idle 或 Run,持有郊狼时间允许跳跃。</summary>
|
||||
public class FallState : PlayerStateBase
|
||||
{
|
||||
public FallState(PlayerController owner) : base(owner) { }
|
||||
|
||||
public override void OnStateEnter()
|
||||
{
|
||||
if (AnimCfg?.Fall != null)
|
||||
Anim.Play(AnimCfg.Fall);
|
||||
}
|
||||
|
||||
public override void OnStateUpdate()
|
||||
{
|
||||
// 郊狼时间跳跃
|
||||
if (Buffer.ConsumeJump() && Move.HasCoyoteTime)
|
||||
{
|
||||
_owner.TransitionTo(_owner.JumpState);
|
||||
return;
|
||||
}
|
||||
|
||||
// 着地
|
||||
if (Move.IsGrounded)
|
||||
{
|
||||
Move.ZeroVelocity();
|
||||
if (Mathf.Abs(Input.MoveInput.x) > 0.1f)
|
||||
_owner.TransitionTo(_owner.RunState);
|
||||
else
|
||||
_owner.TransitionTo(_owner.IdleState);
|
||||
return;
|
||||
}
|
||||
|
||||
// 空中水平移动
|
||||
if (Mathf.Abs(Input.MoveInput.x) > 0.01f)
|
||||
Move.Move(Input.MoveInput.x * (Cfg != null ? Cfg.RunSpeed : 7f));
|
||||
}
|
||||
|
||||
public override void OnStateFixedUpdate()
|
||||
{
|
||||
// 增强下落重力
|
||||
if (Cfg != null && Move.Rb.velocity.y < 0f)
|
||||
{
|
||||
float extraGrav = Physics2D.gravity.y * (Cfg.FallGravityMult - 1f) * Time.fixedDeltaTime;
|
||||
Move.Rb.velocity = new Vector2(
|
||||
Move.Rb.velocity.x,
|
||||
Mathf.Max(Move.Rb.velocity.y + extraGrav, -Cfg.MaxFallSpeed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user