From cb68ad6a2fcf6ec741de3668a63931e4510ea2f5 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 21 May 2026 20:49:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=8E=A9=E5=AE=B6=E7=89=A9?= =?UTF-8?q?=E7=90=86=E7=A7=BB=E5=8A=A8=E9=80=BB=E8=BE=91=EF=BC=8C=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E8=BF=9E=E7=BB=AD=E7=A2=B0=E6=92=9E=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E4=BB=A5=E9=98=B2=E6=AD=A2=E8=A7=92=E8=89=B2=E7=A9=BF=E5=A2=99?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E8=B0=83=E6=95=B4=E5=B9=B3=E5=8F=B0=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E5=8F=A0=E5=8A=A0=E8=A7=84=E5=88=99=E4=BB=A5=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E7=89=A9=E7=90=86=E4=BA=A4=E4=BA=92=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/_Game/Scripts/Player/PlayerMovement.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Assets/_Game/Scripts/Player/PlayerMovement.cs b/Assets/_Game/Scripts/Player/PlayerMovement.cs index cffad50..839f95e 100644 --- a/Assets/_Game/Scripts/Player/PlayerMovement.cs +++ b/Assets/_Game/Scripts/Player/PlayerMovement.cs @@ -87,6 +87,9 @@ namespace BaseGames.Player // SpritePixelSnapper(LateUpdate +1000)在插值结果基础上吸附到像素网格, // 与 CameraPixelSnapper 同格对齐,消除亚像素模糊;停止时 ≤2 帧像素追赶不可感知。 _rb.interpolation = RigidbodyInterpolation2D.Interpolate; + // 开启连续碰撞检测(CCD):Kinematic 移动平台通过 MovePosition 将 Dynamic 角色推向墙体时, + // CCD 会沿移动路径追踪碰撞,确保角色在物理层被墙体表面拦截,而不是在离散步骤中穿透墙体。 + _rb.collisionDetectionMode = CollisionDetectionMode2D.Continuous; } private void FixedUpdate() @@ -135,11 +138,21 @@ namespace BaseGames.Player /// 在无输入时自然减速,保留跳出时的动量。 /// 若当前站在移动平台上,自动叠加 _platformVelocity.x 保持同步; /// _inputVelocityX 只记录玩家输入分量,供 UpdateFacing / ApplyAirDrag 使用。 + /// 当平台速度方向与已贴墙方向相同时,不叠加平台水平速度, + /// 防止速度叠加把角色推入墙体(物理接触已被 CCD 拦截,但速度覆盖会继续施力)。 /// public void Move(float speedX) { _inputVelocityX = speedX; - _rb.velocity = new Vector2(speedX + _platformVelocity.x, _rb.velocity.y); + + // 若平台将角色推向已贴墙一侧,忽略平台水平分量: + // 物理层(CCD + 碰撞体)已阻止角色穿墙,速度层若继续施加同向力, + // 会在每帧产生累积穿透,导致角色卡入或被弹出墙体。 + float platformX = _platformVelocity.x; + if ((platformX > 0f && _isWallRight) || (platformX < 0f && _isWallLeft)) + platformX = 0f; + + _rb.velocity = new Vector2(speedX + platformX, _rb.velocity.y); } ///