PlayerMovementConfigSO.cs
新增 WallHangSpeed = 1f:正常抓墙(低于等于 wallGrabY,可蹬墙跳区间)的缓慢下滑速度 WallSlideSpeed 语义调整为:受限模式(高于 wallGrabY)的较快下滑速度 PlayerMovement.cs ApplyWallSlide() 改为 ApplyWallSlide(float speed),由调用方传入对应速度 WallSlideState.cs OnStateFixedUpdate:正常模式用 WallHangSpeed,受限模式用 WallSlideSpeed(两档清晰分离) 恢复反方向键脱离:脱离时同样调用 StartWallCoyote,wall coyote 窗口内仍能触发蹬墙跳 更新类头注释完整描述脱离方式和下滑速度档位Two wall slide improvements:
This commit is contained in:
@@ -24,6 +24,8 @@ namespace BaseGames.Player
|
||||
// ── 运行时状态 ────────────────────────────────────────────────────────
|
||||
private Rigidbody2D _rb;
|
||||
private float _coyoteTimer;
|
||||
private float _wallCoyoteTimer;
|
||||
private int _wallCoyoteDir; // 离墙时记录的墙壁方向(+1 右 / -1 左)
|
||||
private bool _isGrounded;
|
||||
// Update 中调用 ZeroHorizontalVelocity 后设置此标记;
|
||||
// 下一个 FixedUpdate(-200,先于状态机 -100)读取并清零,
|
||||
@@ -47,6 +49,7 @@ namespace BaseGames.Player
|
||||
[SerializeField] private bool _dbg_IsGrounded;
|
||||
[SerializeField] private bool _dbg_OnOneWayPlatform;
|
||||
[SerializeField] private bool _dbg_HasCoyoteTime;
|
||||
[SerializeField] private bool _dbg_HasWallCoyoteTime;
|
||||
[SerializeField] private bool _dbg_IsWallLeft;
|
||||
[SerializeField] private bool _dbg_IsWallRight;
|
||||
[SerializeField] private bool _dbg_CancelWindowOpen;
|
||||
@@ -55,6 +58,8 @@ namespace BaseGames.Player
|
||||
|
||||
public bool IsGrounded => _isGrounded;
|
||||
public bool HasCoyoteTime => _coyoteTimer > 0f;
|
||||
public bool HasWallCoyoteTime => _wallCoyoteTimer > 0f;
|
||||
public int WallCoyoteDir => _wallCoyoteDir;
|
||||
public bool IsWallLeft => _isWallLeft;
|
||||
public bool IsWallRight => _isWallRight;
|
||||
public bool OnOneWayPlatform => _onOneWayPlatform;
|
||||
@@ -93,12 +98,15 @@ namespace BaseGames.Player
|
||||
else
|
||||
_coyoteTimer = Mathf.Max(0f, _coyoteTimer - Time.fixedDeltaTime);
|
||||
|
||||
_wallCoyoteTimer = Mathf.Max(0f, _wallCoyoteTimer - Time.fixedDeltaTime);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
_dbg_VelocityX = _rb.velocity.x;
|
||||
_dbg_VelocityY = _rb.velocity.y;
|
||||
_dbg_IsGrounded = _isGrounded;
|
||||
_dbg_OnOneWayPlatform = _onOneWayPlatform;
|
||||
_dbg_HasCoyoteTime = _coyoteTimer > 0f;
|
||||
_dbg_HasWallCoyoteTime = _wallCoyoteTimer > 0f;
|
||||
_dbg_IsWallLeft = _isWallLeft;
|
||||
_dbg_IsWallRight = _isWallRight;
|
||||
_dbg_CancelWindowOpen = _cancelWindowOpen;
|
||||
@@ -198,6 +206,21 @@ namespace BaseGames.Player
|
||||
// ── 取消窗口 ──────────────────────────────────────────────────────────
|
||||
public void SetCancelWindowOpen(bool open) => _cancelWindowOpen = open;
|
||||
|
||||
// ── 墙壁土狼时间 ──────────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// 由 WallSlideState 在切换到 FallState 时调用:启动墙壁土狼计时器。
|
||||
/// 窗口内(HasWallCoyoteTime == true)按跳跃键仍可触发蹬墙跳。
|
||||
/// wallDir:+1 = 右墙 / -1 = 左墙。
|
||||
/// </summary>
|
||||
public void StartWallCoyote(int wallDir)
|
||||
{
|
||||
_wallCoyoteTimer = _config.WallCoyoteTime;
|
||||
_wallCoyoteDir = wallDir;
|
||||
}
|
||||
|
||||
/// <summary>消耗墙壁土狼时间,防止同一帧被多次触发。</summary>
|
||||
public void ConsumeWallCoyote() => _wallCoyoteTimer = 0f;
|
||||
|
||||
// ── 冲刺 ──────────────────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// 施加冲刺速度(DashState/DashState 调用)。
|
||||
@@ -210,12 +233,12 @@ namespace BaseGames.Player
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 壁滑:将垂直速度限制为 -WallSlideSpeed(受限抓墙时向下缓慢滑动)。
|
||||
/// WallSlideState.OnStateFixedUpdate 在受限模式下每帧调用。
|
||||
/// 壁滑:将垂直速度限制为 -speed(每帧调用以约束最大下滑速度)。
|
||||
/// WallSlideState.OnStateFixedUpdate 根据正常/受限模式传入不同速度。
|
||||
/// </summary>
|
||||
public void ApplyWallSlide()
|
||||
public void ApplyWallSlide(float speed)
|
||||
{
|
||||
float targetY = -_config.WallSlideSpeed;
|
||||
float targetY = -speed;
|
||||
if (_rb.velocity.y < targetY)
|
||||
_rb.velocity = new Vector2(_rb.velocity.x, targetY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user