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