Меняется таргет камеры (и высота коллайдера) при слайде

This commit is contained in:
MrTorex committed 2025-12-04 21:33:37 +03:00
1 parent eb4dff803e
commit ecff1e69cd
3 files changed
+75 -3

No files matched your search

@@ -23,7 +23,11 @@ namespace Code.Configs
);
public float
slideMinVelocityThreshold = 3f,
slideCooldown = 1.5f;
slideCooldown = 1.5f,
slideColliderHeightScale = 0.5f,
slideCameraOffsetY = -0.5f,
slideEnterDuration = 0.2f,
slideExitDuration = 0.25f;
public float
leanAngle = 25f,
@@ -15,7 +15,7 @@ namespace Code.Gameplay.Character.Controller
* Реализует физическое движение персонажа с использованием Kinematic Character Controller
* Обрабатывает ввод пользователя, применяет движение и вращение с учетом поверхности
*
* Источник: Tvtig, https://www.youtube.com/watch?v=9ibpY64wBYM
* Источник: Tvtig, https://www.youtube.com/watch?v=9ibpY64wBYM
*/
public class CustomCharacterController : MonoBehaviour, ICharacterController
{
@@ -25,6 +25,12 @@ namespace Code.Gameplay.Character.Controller
[SerializeField] private Transform characterTransform; // Трансформ персонажа (с точкой отслеживания камеры)
[SerializeField] private CapsuleCollider _capsuleCollider;
[SerializeField] private Transform _cameraFollowPoint;
private Vector3 _originalColliderCenter;
private float _originalColliderHeight;
private Vector3 _originalFollowPointLocalPosition;
// Подсистемы
private CharacterInputHandler _inputHandler;
private DashMechanic _dashMechanic;
@@ -92,6 +98,17 @@ namespace Code.Gameplay.Character.Controller
motor.Transform.rotation; // Начальное вращение совпадает с персонажемс
_wallLeanMechanic.SetModel(characterTransform);
_wallRunningMechanic.Initialize(motor);
if (_capsuleCollider != null)
{
_originalColliderCenter = _capsuleCollider.center;
_originalColliderHeight = _capsuleCollider.height;
}
if (_cameraFollowPoint != null)
{
_originalFollowPointLocalPosition = _cameraFollowPoint.localPosition;
}
}
// Текущий режим камеры для адаптации поведения
@@ -185,11 +202,26 @@ namespace Code.Gameplay.Character.Controller
}
if (!_slideMechanic.IsSliding)
{
_slideMechanic.TryStartSlide(motor, _currentCameraMode, _inputHandler.FirstPersonCameraRotation, _inputHandler.LookInputVector);
if (_slideMechanic.IsSliding)
{
EnterSlideState();
}
else
{
ExitSlideState();
}
}
else
{
_slideMechanic.HandleSlide(ref currentVelocity, deltaTime, motor);
return;
if (!_slideMechanic.IsSliding)
{
ExitSlideState();
}
}
// === WALL RUNNING: обработка состояния ===
@@ -226,6 +258,40 @@ namespace Code.Gameplay.Character.Controller
isAbilitiesBlocked = true;
abilityBlockTimer = duration;
}
private void EnterSlideState()
{
if (_capsuleCollider)
{
var newHeight = _originalColliderHeight * _characterConfig.slideColliderHeightScale;
_capsuleCollider.height = newHeight;
var newCenterY = newHeight * 0.5f - _originalColliderHeight * 0.5f;
_capsuleCollider.center = _originalColliderCenter + Vector3.up * newCenterY;
}
if (!_cameraFollowPoint) return;
var offset = Vector3.up * _characterConfig.slideCameraOffsetY;
_cameraFollowPoint.localPosition = _originalFollowPointLocalPosition + offset;
}
private void ExitSlideState()
{
if (_capsuleCollider)
{
_capsuleCollider.height = _originalColliderHeight;
_capsuleCollider.center = _originalColliderCenter;
}
if (_cameraFollowPoint)
{
_cameraFollowPoint.localPosition = _originalFollowPointLocalPosition;
}
}
public void BeforeCharacterUpdate(float deltaTime)
{
@@ -173,6 +173,8 @@ MonoBehaviour:
m_EditorClassIdentifier: Assembly-CSharp::Code.Gameplay.Player.CharacterController
motor: {fileID: 8476708390679839925}
characterTransform: {fileID: 4122797476271397740}
_capsuleCollider: {fileID: 8541228187116599584}
_cameraFollowPoint: {fileID: 1047840484662430186}
--- !u!114 &3283650228831796584
MonoBehaviour:
m_ObjectHideFlags: 0