Files
zeling_v2/Assets/_Game/Scripts/Player/States/RunState.cs
Joywayer 2a6a0b1861 feat: 实现抓墙高度记忆、背墙跳/对墙跳、蹬墙后自动抓墙
- PlayerController: 添加 wallGrabY/wallGrabDir/isPostWallJump 字段及 API
- WallSlideState: 高度限制(超限强制下滑不可蹬跳)+ 静止悬挂 + 反向键释放
- WallJumpState: 区分背墙跳(WallJumpAwayForce)/对墙跳(WallJumpBackForce)
  蹬墙后标记 PostWallJump 允许空中自动抓墙;恢复空中冲刺次数
- FallState/JumpState: 新增抓墙入口(朝向按键 OR PostWallJump 自动抓墙)
- PlayerMovement.WallJump: 增加 jumpAway 参数区分两种跳跃力
- IdleState/RunState: 落地时重置抓墙记录和蹬墙跳标记

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-19 12:12:24 +08:00

59 lines
1.9 KiB
C#

using UnityEngine;
namespace BaseGames.Player.States
{
/// <summary>跑步状态。播放 Run 动画并驱动水平移动。</summary>
public class RunState : PlayerStateBase
{
public RunState(PlayerController owner) : base(owner) { }
public override void OnStateEnter()
{
if (AnimCfg?.Run != null)
Anim.Play(AnimCfg.Run);
// 落地时重置空中能力计数器及抓墙记录(水平落地直接进入 RunState 时)
Owner.GetState<AerialDashState>()?.ResetAerialDashes();
Owner.ResetAirJumps();
Owner.ResetWallGrab();
Owner.SetPostWallJump(false);
}
public override void OnStateUpdate()
{
if (!Move.IsGrounded)
{
_owner.TransitionTo(_owner.GetState<FallState>());
return;
}
if (Buffer.ConsumeJump())
{
_owner.TransitionTo(_owner.GetState<JumpState>());
return;
}
// 地面冲刺:需解锁 Dash 能力,且冲刺不在冷却
if (Buffer.ConsumeDash()
&& Stats != null && Stats.HasAbility(AbilityType.Dash)
&& Owner.GetState<DashState>() is { CanDash: true } dashState)
{
_owner.TransitionTo(dashState);
return;
}
if (Mathf.Abs(Input.MoveInput.x) < 0.1f)
{
Move.ZeroHorizontalVelocity();
_owner.TransitionTo(_owner.GetState<IdleState>());
return;
}
}
public override void OnStateFixedUpdate()
{
float inputX = Input.MoveInput.x;
if (Mathf.Abs(inputX) > 0.1f)
Move.Move(inputX * Cfg.RunSpeed);
else
Move.ZeroHorizontalVelocity();
}
}
}