Something fixed
This commit is contained in:
1 parent
f40a10912c
commit
7d236d14cd
72 files changed
+270482
-11409
No files matched your search
@@ -9,7 +9,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
var snapshot = new AttackBattleActionData()
|
||||
{
|
||||
TotalFrames = TotalFrames,
|
||||
CurrentFrame = CurrentFrame
|
||||
CurrentFrame = CurrentFrame,
|
||||
TransitionFrames = TransitionFrames,
|
||||
};
|
||||
|
||||
return snapshot;
|
||||
@@ -21,6 +22,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
TotalFrames = neededSnapshot.TotalFrames;
|
||||
CurrentFrame = neededSnapshot.CurrentFrame;
|
||||
TransitionFrames = neededSnapshot.TransitionFrames;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,10 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
Rotation = Rotation,
|
||||
Path = Path,
|
||||
Corners = cornersCopy,
|
||||
CurrentCornerIndex = CurrentCornerIndex
|
||||
WasStarted = WasStarted,
|
||||
CurrentCornerIndex = CurrentCornerIndex,
|
||||
IsRotateOnly = IsRotateOnly,
|
||||
CurrentFrame = CurrentFrame
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,10 +44,13 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
if (snapshot is not MovementBattleActionData moveSnapshot) return;
|
||||
|
||||
CurrentFrame = moveSnapshot.CurrentFrame;
|
||||
Position = moveSnapshot.Position;
|
||||
Rotation = moveSnapshot.Rotation;
|
||||
Path = moveSnapshot.Path;
|
||||
CurrentCornerIndex = moveSnapshot.CurrentCornerIndex;
|
||||
WasStarted = moveSnapshot.WasStarted;
|
||||
IsRotateOnly = moveSnapshot.IsRotateOnly;
|
||||
|
||||
if (moveSnapshot.Corners != null)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
var snapshot = new AttackBattleActionData()
|
||||
{
|
||||
TotalFrames = TotalFrames,
|
||||
CurrentFrame = CurrentFrame
|
||||
CurrentFrame = CurrentFrame,
|
||||
TransitionFrames = TransitionFrames,
|
||||
};
|
||||
|
||||
return snapshot;
|
||||
@@ -21,6 +22,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
TotalFrames = neededSnapshot.TotalFrames;
|
||||
CurrentFrame = neededSnapshot.CurrentFrame;
|
||||
TransitionFrames = neededSnapshot.TransitionFrames;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
return new WaitBattleActionData
|
||||
{
|
||||
TotalFrames = TotalFrames,
|
||||
WaitFrames = WaitFrames
|
||||
WaitFrames = WaitFrames,
|
||||
StartedWaiting = StartedWaiting
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,6 +21,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
if (snapshot is not WaitBattleActionData waitSnapshot) return;
|
||||
|
||||
WaitFrames = waitSnapshot.WaitFrames;
|
||||
StartedWaiting = waitSnapshot.StartedWaiting;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,14 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
private const float StoppingDistance = 0.15f;
|
||||
private const float RotateDistance = 1f;
|
||||
private const float NavMeshSampleRadius = 1.5f;
|
||||
private const float TurnSpeedDegPerSec = 720f; // Скорость вращения на месте (градусов/сек)
|
||||
private const float TurnSpeedDegPerSec = 720f;
|
||||
|
||||
private int MoveStateHash => Animator.StringToHash("WalkBlend");
|
||||
|
||||
public override BattleActionType ActionType => BattleActionType.Move;
|
||||
public override DeciderType DeciderType => DeciderType.Position;
|
||||
|
||||
// Ультра супер мега конструкция для проверки и утверждения точной позиции. Но не работающая.
|
||||
public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result)
|
||||
{
|
||||
MovementBattleActionData data = new();
|
||||
@@ -27,12 +28,12 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
Vector3 startPos = entity.KinematicCharacterMotor.TransientPosition;
|
||||
Vector3 targetPos = positionDecisionResult.Position;
|
||||
|
||||
// 1. Проверяем дистанцию в плоскости XZ
|
||||
Vector3 toTargetXZ = targetPos - startPos;
|
||||
toTargetXZ.y = 0f;
|
||||
|
||||
Debug.DrawLine(startPos, targetPos, Color.red, 5f);
|
||||
|
||||
float distanceXZ = toTargetXZ.magnitude;
|
||||
|
||||
// ЕСЛИ ВПЛОТНУЮ: отключаем перемещение, оставляем только поворот
|
||||
if (distanceXZ <= StoppingDistance)
|
||||
{
|
||||
data.IsRotateOnly = true;
|
||||
@@ -40,7 +41,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
float angle = Quaternion.Angle(entity.KinematicCharacterMotor.TransientRotation, positionDecisionResult.Rotation);
|
||||
|
||||
// Если персонаж уже смотрит в нужную сторону — 0 кадров
|
||||
if (angle < 1f)
|
||||
{
|
||||
data.TotalFrames = 0;
|
||||
@@ -54,7 +54,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
return data;
|
||||
}
|
||||
|
||||
// 2. ДВИЖЕНИЕ: проецируем точки строго на полигоны NavMesh
|
||||
bool hasStart = NavMesh.SamplePosition(startPos, out NavMeshHit startHit, NavMeshSampleRadius, NavMesh.AllAreas);
|
||||
bool hasTarget = NavMesh.SamplePosition(targetPos, out NavMeshHit targetHit, NavMeshSampleRadius, NavMesh.AllAreas);
|
||||
|
||||
@@ -67,7 +66,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
Vector3 validStart = startHit.position;
|
||||
Vector3 validTarget = targetHit.position;
|
||||
|
||||
// 3. Прямая видимость: если препятствий нет, идём по идеальной прямой без квантования полигонов NavMesh
|
||||
if (!NavMesh.Raycast(validStart, validTarget, out _, NavMesh.AllAreas))
|
||||
{
|
||||
data.Corners = new[] { startPos, validTarget };
|
||||
@@ -76,13 +74,11 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
return data;
|
||||
}
|
||||
|
||||
// 4. Обход препятствий: строим путь и отсекаем частичные обрубки (PathPartial)
|
||||
NavMeshPath path = new();
|
||||
if (NavMesh.CalculatePath(validStart, validTarget, NavMesh.AllAreas, path)
|
||||
&& path.status == NavMeshPathStatus.PathComplete
|
||||
&& path.corners.Length > 1)
|
||||
{
|
||||
// Привязываем нулевую и финальную точки к фактическим координатам
|
||||
path.corners[0] = startPos;
|
||||
path.corners[^1] = validTarget;
|
||||
|
||||
@@ -92,7 +88,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
}
|
||||
else
|
||||
{
|
||||
// Если NavMesh не смог построить полный путь (PathPartial/Invalid) — не даём ходить огрызками
|
||||
data.TotalFrames = 0;
|
||||
}
|
||||
|
||||
@@ -114,9 +109,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
var movementController = entity.MovementController;
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// РЕЖИМ 1: ТОЛЬКО ПОВОРОТ НА МЕСТЕ (КОГДА ПОЗИЦИЯ ВПЛОТНУЮ)
|
||||
// -------------------------------------------------------------
|
||||
if (movementActionData.IsRotateOnly)
|
||||
{
|
||||
movementActionData.CurrentFrame++;
|
||||
@@ -144,19 +136,18 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log("Rotated");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// РЕЖИМ 2: ПЕРЕДВИЖЕНИЕ ПО ПУТИ
|
||||
// -------------------------------------------------------------
|
||||
if (movementActionData.Corners == null || movementActionData.CurrentCornerIndex >= movementActionData.Corners.Length)
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
StopMovementAndFinish(movementController);
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log("Wrong index");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -169,7 +160,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
Vector3 currentPos = entity.KinematicCharacterMotor.TransientPosition;
|
||||
|
||||
// Пропускаем пройденные углы
|
||||
while (movementActionData.CurrentCornerIndex < movementActionData.Corners.Length)
|
||||
{
|
||||
Vector3 toCorner = movementActionData.Corners[movementActionData.CurrentCornerIndex] - currentPos;
|
||||
@@ -181,7 +171,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
break;
|
||||
}
|
||||
|
||||
// Если все точки пройдены до шага симуляции
|
||||
if (movementActionData.CurrentCornerIndex >= movementActionData.Corners.Length)
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
@@ -193,6 +182,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
);
|
||||
|
||||
battleActionData.Finished = true;
|
||||
Debug.Log("Last corner");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -232,7 +222,6 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
KinematicCharacterSystem.PhysicsMovers
|
||||
);
|
||||
|
||||
// Проверка достижения конечной точки после физического тика
|
||||
Vector3 postMovePos = movementController.Motor.TransientPosition;
|
||||
Vector3 toFinal = movementActionData.Corners[^1] - postMovePos;
|
||||
toFinal.y = 0f;
|
||||
@@ -241,6 +230,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
entity.KinematicCharacterMotor.SetRotation(positionDecisionResult.Rotation);
|
||||
StopMovementAndFinish(movementController);
|
||||
Debug.Log("Very Last corner");
|
||||
battleActionData.Finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,12 @@ namespace Code.OfficeGame.BattleMode.Actions.Deciders
|
||||
var position = _cameraStateMachine.Camera.transform.position;
|
||||
var direction = _cameraStateMachine.Camera.transform.forward;
|
||||
|
||||
var hitCount = Physics.RaycastNonAlloc(position, direction, _hitBuffer, Mathf.Infinity, _navMeshMask);
|
||||
var hitCount = Physics.RaycastNonAlloc(
|
||||
position,
|
||||
direction,
|
||||
_hitBuffer,
|
||||
Mathf.Infinity,
|
||||
_navMeshMask);
|
||||
|
||||
if (hitCount == 0
|
||||
|| _entityPosition == Vector3.zero) return;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user