Something fixed

This commit is contained in:
ThomasCharester committed 2026-11-10 00:28:25 +03:00
1 parent f40a10912c
commit 7d236d14cd
72 files changed
+270482 -11409

No files matched your search

@@ -1,3 +1,4 @@
using Code.Game.Gameplay.Player;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
@@ -6,7 +7,9 @@ namespace Code.OfficeGame.BattleMode.Actions
{
public Vector3 Position;
public Quaternion Rotation;
public AnimatorSnapshot AnimatorSnapshot;
public MovementControllerSnapshot ControllerSnapshot;
public static EntitySnapshot GetSnapshot(EntityProperties entityProperties)
{
@@ -14,7 +17,8 @@ namespace Code.OfficeGame.BattleMode.Actions
{
Position = entityProperties.KinematicCharacterMotor.TransientPosition,
Rotation = entityProperties.KinematicCharacterMotor.TransientRotation,
AnimatorSnapshot = AnimatorSnapshot.GetSnapshot(entityProperties.animator)
AnimatorSnapshot = AnimatorSnapshot.GetSnapshot(entityProperties.animator),
ControllerSnapshot = MovementControllerSnapshot.GetSnapshot(entityProperties.MovementController)
};
}
@@ -23,7 +27,9 @@ namespace Code.OfficeGame.BattleMode.Actions
// 1. Возвращаем капсулу KCC
entityProperties.KinematicCharacterMotor.SetPositionAndRotation(snapshot.Position, snapshot.Rotation);
entityProperties.KinematicCharacterMotor.BaseVelocity = Vector3.zero;
snapshot.ControllerSnapshot.RestoreSnapshot(entityProperties.MovementController);
// 2. Возвращаем позу и локальное смещение меша
snapshot.AnimatorSnapshot.RestoreTo(entityProperties.animator);
@@ -120,7 +126,6 @@ namespace Code.OfficeGame.BattleMode.Actions
targetAnimator.Rebind();
// Отключаем applyRootMotion на время Update(0f), чтобы Play() не начислил дельту смещения
bool prevRootMotion = targetAnimator.applyRootMotion;
targetAnimator.applyRootMotion = false;
targetAnimator.speed = _speed;
@@ -162,7 +167,6 @@ namespace Code.OfficeGame.BattleMode.Actions
targetAnimator.Update(0f);
// ОБЯЗАТЕЛЬНО восстанавливаем сохраненные локальные координаты меша после Update(0f)!
Transform targetTransform = targetAnimator.transform;
targetTransform.localPosition = _localPosition;
targetTransform.localRotation = _localRotation;
@@ -170,4 +174,27 @@ namespace Code.OfficeGame.BattleMode.Actions
targetAnimator.applyRootMotion = prevRootMotion;
}
}
public struct MovementControllerSnapshot
{
public Vector3 Velocity;
public Vector3 LookInput;
public Vector3 MoveInput;
public static MovementControllerSnapshot GetSnapshot(MovementController movementController)
{
return new()
{
Velocity = movementController.InternalVelocityAdd,
MoveInput = movementController.MoveInputVector,
LookInput = movementController.LookInputVector
};
}
public void RestoreSnapshot(MovementController movementController)
{
movementController.InternalVelocityAdd = Velocity;
movementController.MoveInputVector = MoveInput;
movementController.LookInputVector = LookInput;
}
}
}