Something fixed
This commit is contained in:
1 parent
f40a10912c
commit
7d236d14cd
72 files changed
+270482
-11409
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user