修复内容:
PlayerMovement:新增 _facingLocked 字段 + LockFacing(bool) 方法;UpdateFacing() 锁定时直接返回 WallSlideState:OnStateEnter 调用 LockFacing(true) + FlipFacing(_wallDir);OnStateExit 调用 LockFacing(false) 解锁 WallJumpState:OnStateEnter 保险性再调一次 LockFacing(false);WallJumpAway/Toward 同步写入 _inputVelocityX,确保解锁后 UpdateFacing 朝向正确(背墙跳 = 离墙方向,对墙跳 = 朝墙方向)
This commit is contained in:
@@ -43,6 +43,7 @@ namespace BaseGames.Player
|
||||
private bool _isWallRight;
|
||||
private bool _onOneWayPlatform;
|
||||
private int _facingDirection = 1;
|
||||
private bool _facingLocked; // 为 true 时 UpdateFacing() 不覆盖朝向
|
||||
private bool _cancelWindowOpen;
|
||||
private SurfaceType _currentSurface = SurfaceType.Ground;
|
||||
private readonly Collider2D[] _groundBuffer = new Collider2D[4];
|
||||
@@ -213,6 +214,7 @@ namespace BaseGames.Player
|
||||
// ── 朝向 ──────────────────────────────────────────────────────────────
|
||||
public void UpdateFacing()
|
||||
{
|
||||
if (_facingLocked) return;
|
||||
// 读取玩家输入速度(不含平台分量),避免平台横向运动驱动朝向翻转。
|
||||
float vx = _inputVelocityX;
|
||||
if (Mathf.Abs(vx) < 0.1f) return;
|
||||
@@ -247,6 +249,13 @@ namespace BaseGames.Player
|
||||
transform.localScale = new Vector3(dir, 1f, 1f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 锁定/解锁自动朝向(UpdateFacing)。
|
||||
/// 传入 true 后 UpdateFacing 不再根据输入速度覆盖朝向,
|
||||
/// 直到传入 false 解锁。适用于抓墙、蹬墙跳等需要手动控制朝向的状态。
|
||||
/// </summary>
|
||||
public void LockFacing(bool locked) => _facingLocked = locked;
|
||||
|
||||
// ── 取消窗口 ──────────────────────────────────────────────────────────
|
||||
public void SetCancelWindowOpen(bool open) => _cancelWindowOpen = open;
|
||||
|
||||
@@ -318,7 +327,8 @@ namespace BaseGames.Player
|
||||
/// </summary>
|
||||
public void WallJumpAway(int wallDir)
|
||||
{
|
||||
_rb.velocity = new Vector2(-wallDir * _config.WallJumpAwayForceX, _config.WallJumpAwayForceY);
|
||||
_inputVelocityX = -wallDir * _config.WallJumpAwayForceX;
|
||||
_rb.velocity = new Vector2(_inputVelocityX, _config.WallJumpAwayForceY);
|
||||
_coyoteTimer = 0f;
|
||||
}
|
||||
|
||||
@@ -328,7 +338,8 @@ namespace BaseGames.Player
|
||||
/// </summary>
|
||||
public void WallJumpToward(int wallDir)
|
||||
{
|
||||
_rb.velocity = new Vector2(wallDir * _config.WallJumpTowardForceX, _config.WallJumpTowardForceY);
|
||||
_inputVelocityX = wallDir * _config.WallJumpTowardForceX;
|
||||
_rb.velocity = new Vector2(_inputVelocityX, _config.WallJumpTowardForceY);
|
||||
_coyoteTimer = 0f;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user