From 2cca6d8ffb5b24e5168c0f75f5e388aaebb3593a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C5=A1a=20Ceviel?= Date: Fri, 5 Dec 2025 14:43:04 +0300 Subject: [PATCH] siski --- .../Assets/Code/Configs/CharacterConfig.cs | 4 ++- .../Abilities/WallRunningMechanic.cs | 26 ++++++++++++++++--- .../Controller/CustomCharacterController.cs | 6 +++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Game/CourierOld/Assets/Code/Configs/CharacterConfig.cs b/Game/CourierOld/Assets/Code/Configs/CharacterConfig.cs index c9d9ec6..f261946 100644 --- a/Game/CourierOld/Assets/Code/Configs/CharacterConfig.cs +++ b/Game/CourierOld/Assets/Code/Configs/CharacterConfig.cs @@ -48,6 +48,8 @@ namespace Code.Configs wallRunAcceleration = 25f, wallRunGravityScale = 0.25f, wallDetachImpulse = 7f, - wallContactAngleThreshold = 45f; + wallContactAngleThreshold = 45f, + minLookWithNormal = 30f, + maxLookWithNormal = 60f; } } \ No newline at end of file diff --git a/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/Abilities/WallRunningMechanic.cs b/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/Abilities/WallRunningMechanic.cs index 33470db..d4ca2e7 100644 --- a/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/Abilities/WallRunningMechanic.cs +++ b/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/Abilities/WallRunningMechanic.cs @@ -22,6 +22,11 @@ namespace Code.Gameplay.Character.Controller.Abilities private float _surfaceAngleCos; private bool _canWallRun; + + private readonly float _minLookAngleToWallPlane; + private readonly float _maxLookAngleToWallPlane; + private float _minLookDotWithNormal; + private float _maxLookDotWithNormal; private KinematicCharacterMotor _motor; @@ -33,7 +38,9 @@ namespace Code.Gameplay.Character.Controller.Abilities float wallRunAcceleration, float wallRunGravityScale, float wallDetachImpulse, - float wallContactAngleThreshold) + float wallContactAngleThreshold, + float minLookAngleToWallPlane, + float maxLookAngleToWallPlane) { _maxWallRunTime = maxWallRunTime; _wallRunSpeed = wallRunSpeed; @@ -41,12 +48,20 @@ namespace Code.Gameplay.Character.Controller.Abilities _wallRunGravityScale = wallRunGravityScale; _wallDetachImpulse = wallDetachImpulse; _wallContactAngleThreshold = wallContactAngleThreshold; + _minLookAngleToWallPlane = Mathf.Clamp(minLookAngleToWallPlane, 0f, 90f); + _maxLookAngleToWallPlane = Mathf.Clamp(maxLookAngleToWallPlane, 0f, 90f); } public void Initialize(KinematicCharacterMotor motor) { _motor = motor; _surfaceAngleCos = Mathf.Cos(Mathf.Deg2Rad * _wallContactAngleThreshold); + + var minAngleWithNormal = 90f - _maxLookAngleToWallPlane; + var maxAngleWithNormal = 90f - _minLookAngleToWallPlane; + + _maxLookDotWithNormal = Mathf.Cos(Mathf.Deg2Rad * minAngleWithNormal); + _minLookDotWithNormal = Mathf.Cos(Mathf.Deg2Rad * maxAngleWithNormal); } public void Tick(float deltaTime) @@ -60,13 +75,12 @@ namespace Code.Gameplay.Character.Controller.Abilities } } - public bool TryStartWallRun(Vector3 hitNormal, Vector3 hitPoint) + public bool TryStartWallRun(Vector3 hitNormal, Vector3 hitPoint, Vector3 lookDirection) { if (IsWallRunning) return false; var dotWithUp = Vector3.Dot(hitNormal, _motor.CharacterUp); var isWall = Mathf.Abs(dotWithUp) < _surfaceAngleCos; - if (!isWall) return false; if (_motor.GroundingStatus.IsStableOnGround) return false; @@ -74,6 +88,12 @@ namespace Code.Gameplay.Character.Controller.Abilities var velocityIntoWall = Vector3.Dot(_motor.Velocity, -hitNormal); if (velocityIntoWall < 1f) return false; + var lookDirNormalized = lookDirection.normalized; + var dotWithNormal = Vector3.Dot(lookDirNormalized, hitNormal); + + if (Mathf.Abs(dotWithNormal) < _minLookDotWithNormal || Mathf.Abs(dotWithNormal) > _maxLookDotWithNormal) + return false; + StartWallRun(hitNormal, hitPoint); return true; } diff --git a/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/CustomCharacterController.cs b/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/CustomCharacterController.cs index 95999ae..aa69d5c 100644 --- a/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/CustomCharacterController.cs +++ b/Game/CourierOld/Assets/Code/Gameplay/Character/Controller/CustomCharacterController.cs @@ -88,7 +88,9 @@ namespace Code.Gameplay.Character.Controller _characterConfig.wallRunAcceleration, _characterConfig.wallRunGravityScale, _characterConfig.wallDetachImpulse, - _characterConfig.wallContactAngleThreshold + _characterConfig.wallContactAngleThreshold, + _characterConfig.minLookWithNormal, + _characterConfig.maxLookWithNormal ); _wallLeanMechanic = new WallLeanMechanic( _characterConfig.leanAngle, @@ -422,7 +424,7 @@ namespace Code.Gameplay.Character.Controller public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport) { - if (_wallRunningMechanic.TryStartWallRun(hitNormal, hitPoint)) return; + if (_wallRunningMechanic.TryStartWallRun(hitNormal, hitPoint, motor.CharacterForward)) return; var horizontalVelocity = Vector3.ProjectOnPlane(motor.Velocity, motor.CharacterUp).normalized; var velocitySqrMag = horizontalVelocity.sqrMagnitude;