При касани с землёй прекращается залазание, убрано движение на A/D
This commit is contained in:
1 parent
4c16a63abd
commit
eb4dff803e
2 files changed
+17
-27
No files matched your search
+16
-26
@@ -1,4 +1,3 @@
|
||||
using Code.Gameplay.Character.Controller.Input;
|
||||
using Code.Gameplay.Character.Core;
|
||||
using KinematicCharacterController;
|
||||
using UnityEngine;
|
||||
@@ -25,7 +24,6 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
private bool _canWallRun;
|
||||
|
||||
private KinematicCharacterMotor _motor;
|
||||
private CharacterInputHandler _inputHandler;
|
||||
|
||||
public bool IsWallRunning { get; private set; }
|
||||
|
||||
@@ -45,10 +43,9 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
_wallContactAngleThreshold = wallContactAngleThreshold;
|
||||
}
|
||||
|
||||
public void Initialize(KinematicCharacterMotor motor, CharacterInputHandler inputHandler)
|
||||
public void Initialize(KinematicCharacterMotor motor)
|
||||
{
|
||||
_motor = motor;
|
||||
_inputHandler = inputHandler;
|
||||
_surfaceAngleCos = Mathf.Cos(Mathf.Deg2Rad * _wallContactAngleThreshold);
|
||||
}
|
||||
|
||||
@@ -88,13 +85,16 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
_wallNormal = wallNormal.normalized;
|
||||
_wallContactPoint = contactPoint;
|
||||
|
||||
if (_wallTangentUp.sqrMagnitude < 0.01f) _wallTangentUp = Vector3.up;
|
||||
var forwardInWallPlane = Vector3.ProjectOnPlane(_motor.CharacterForward, _wallNormal).normalized;
|
||||
if (forwardInWallPlane.sqrMagnitude < 0.01f)
|
||||
{
|
||||
var fallbackRight = Vector3.Cross(_wallNormal, _wallTangentUp).normalized;
|
||||
var dotWithRight = Vector3.Dot(_motor.CharacterRight, _wallNormal);
|
||||
forwardInWallPlane = dotWithRight < 0 ? fallbackRight : -fallbackRight;
|
||||
}
|
||||
|
||||
_wallTangentRight = Vector3.Cross(_wallNormal, _wallTangentUp).normalized;
|
||||
|
||||
_wallTangentUp = Vector3.Cross(_wallTangentRight, _wallNormal).normalized;
|
||||
if (Vector3.Dot(_wallTangentUp, Vector3.up) < 0)
|
||||
_wallTangentUp = -_wallTangentUp;
|
||||
_wallTangentRight = forwardInWallPlane;
|
||||
_wallTangentUp = Vector3.Cross(_wallTangentRight, -_wallNormal).normalized;
|
||||
|
||||
_motor.ForceUnground();
|
||||
}
|
||||
@@ -104,23 +104,11 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
if (!IsWallRunning) return;
|
||||
if (!IsWallStillPresent()) { DetachFromWall(false); return; }
|
||||
|
||||
var moveInputWorld = _inputHandler.MoveInputVector;
|
||||
var moveInWallPlane = Vector3.ProjectOnPlane(moveInputWorld, _wallNormal);
|
||||
var forwardInput = inputs.MoveAxisForward;
|
||||
var moveDirection = _wallTangentRight * forwardInput;
|
||||
|
||||
var wsMove = Vector3.Project(moveInWallPlane, _wallTangentRight);
|
||||
|
||||
var ad = inputs.MoveAxisRight;
|
||||
|
||||
var sideDot = Vector3.Dot(_wallNormal, _motor.CharacterRight);
|
||||
if (sideDot < 0)
|
||||
ad = -ad;
|
||||
|
||||
var adMove = _wallTangentUp * (-ad);
|
||||
|
||||
var finalMove = wsMove + adMove;
|
||||
finalMove = finalMove.normalized * moveInputWorld.magnitude;
|
||||
|
||||
var targetVelocity = finalMove * _wallRunSpeed;
|
||||
var targetSpeed = moveDirection.sqrMagnitude > 0.01f ? _wallRunSpeed : currentVelocity.magnitude;
|
||||
var targetVelocity = moveDirection.normalized * targetSpeed;
|
||||
|
||||
currentVelocity = Vector3.Lerp(
|
||||
currentVelocity,
|
||||
@@ -147,6 +135,8 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
{
|
||||
if (!_motor) return false;
|
||||
|
||||
if (_motor.GroundingStatus.IsStableOnGround) return false;
|
||||
|
||||
var characterCenter = _motor.TransientPosition;
|
||||
var characterRight = _motor.CharacterRight;
|
||||
var characterUp = _motor.CharacterUp;
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ namespace Code.Gameplay.Character.Controller
|
||||
_inputHandler.FirstPersonCameraRotation =
|
||||
motor.Transform.rotation; // Начальное вращение совпадает с персонажемс
|
||||
_wallLeanMechanic.SetModel(characterTransform);
|
||||
_wallRunningMechanic.Initialize(motor, _inputHandler);
|
||||
_wallRunningMechanic.Initialize(motor);
|
||||
}
|
||||
|
||||
// Текущий режим камеры для адаптации поведения
|
||||
|
||||
Reference in new issue
Block a user