Более менее пашет

This commit is contained in:
bybohka committed 2026-11-20 05:08:26 +03:00
1 parent eed6b79efc
commit 33168b98d1
26 files changed
+443071 -19380

No files matched your search

@@ -92,12 +92,12 @@ public class PlayerInteractor : MonoBehaviour
// Сливная пробка картера под днищем (луч может проходить под порогом)
if (TryDrainPlug(ray, playerRoot)) return;
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer, QueryTriggerInteraction.Collide))
if (TryRaycastPrioritized(ray, out RaycastHit hit))
{
CurrentTarget = hit.collider.gameObject;
// 1. ТОЧНЫЙ ПОИСК БЛИЖАЙШЕГО К ПРИЦЕЛУ БОЛТА
WheelBolt bestBolt = FindClosestBoltToRay(ray, hit.point);
WheelBolt bestBolt = FindClosestBoltToRay(ray, hit.point, hit.collider);
if (bestBolt != null)
{
ResetProgressTargets();
@@ -226,6 +226,67 @@ public class PlayerInteractor : MonoBehaviour
uiManager?.HidePrompt();
}
private bool TryRaycastPrioritized(Ray ray, out RaycastHit bestHit)
{
bestHit = default;
RaycastHit[] hits = Physics.RaycastAll(ray, interactRange, interactableLayer, QueryTriggerInteraction.Collide);
if (hits.Length == 0) return false;
System.Array.Sort(hits, (a, b) => a.distance.CompareTo(b.distance));
int bestPriority = int.MaxValue;
bool found = false;
bool blockedByClosedHood = false;
foreach (RaycastHit h in hits)
{
if (h.collider.transform.root == transform.root) continue; // пропускаем игрока
// Если на пути закрытый капот — подкапотку за ним не ловим, но сам капот доступен
CarPartAnimator anim = h.collider.GetComponentInParent<CarPartAnimator>();
if (anim != null && !anim.IsOpen && anim.name.ToLowerInvariant().Contains("hood"))
blockedByClosedHood = true;
bool isUnderHood = h.collider.GetComponentInParent<CarFluidCap>() != null
|| h.collider.GetComponentInParent<OilDipstick>() != null
|| h.collider.GetComponentInParent<EnginePart>() != null;
if (isUnderHood && blockedByClosedHood) continue;
// Твёрдое препятствие не от машины и не интерактивное (стена/пол) — дальше не пробиваем
if (!h.collider.isTrigger
&& h.collider.GetComponentInParent<VehicleInteraction>() == null
&& h.collider.GetComponentInParent<IInteractable>() == null)
{
break;
}
int prio = 50;
if (h.collider.GetComponentInParent<CarFluidCap>() != null
|| h.collider.GetComponentInParent<OilDipstick>() != null)
prio = 10;
else if (h.collider.GetComponentInParent<EnginePart>() != null)
prio = 15;
else if (h.collider.GetComponentInParent<CarJack>() != null
|| h.collider.GetComponentInParent<WheelBrickSupport>() != null)
prio = 20;
else
{
CarPart cp = h.collider.GetComponentInParent<CarPart>();
if (cp != null) prio = cp.IsWheel ? 25 : 30;
else if (h.collider.GetComponentInParent<IInteractable>() != null) prio = 35;
else if (h.collider.GetComponentInParent<VehicleInteraction>() != null) prio = 40;
}
if (prio < bestPriority)
{
bestPriority = prio;
bestHit = h;
found = true;
}
}
return found;
}
private bool TryDrainPlug(Ray ray, GameObject playerRoot)
{
RaycastHit[] hits = Physics.RaycastAll(ray, interactRange, interactableLayer, QueryTriggerInteraction.Collide);
@@ -246,36 +307,41 @@ public class PlayerInteractor : MonoBehaviour
return false;
}
private WheelBolt FindClosestBoltToRay(Ray ray, Vector3 hitPoint)
private WheelBolt FindClosestBoltToRay(Ray ray, Vector3 hitPoint, Collider hitCollider)
{
WheelBolt closest = null;
float minRayDist = 0.085f; // Радиус захвата точки прицела (8.5 см вокруг луча)
float minRayDist = 0.085f;
bool hasWrench = PlayerToolManager.Instance != null
&& PlayerToolManager.Instance.currentTool == ToolType.Wrench;
void CheckWheel(CarPart part)
{
if (part == null || part.TotalBoltsCount == 0 || part.State != PartState.Installed) return;
foreach (WheelBolt b in part.GetComponentsInChildren<WheelBolt>(true))
{
if (b == null || !b.IsAvailableForAim) continue;
// Пустые гнёзда болтов подсвечиваем и ловим только с ключом, чтобы руками можно было снять колесо
if (!b.IsTightened && !hasWrench) continue;
float distToRay = Vector3.Cross(ray.direction, b.WorldBoltCenter - ray.origin).magnitude;
if (distToRay < minRayDist)
{
minRayDist = distToRay;
closest = b;
}
}
}
if (hitCollider != null)
CheckWheel(hitCollider.GetComponentInParent<CarPart>());
// 1. Ищем колесо в радиусе попадания луча и проверяем ВСЕ его дочерние болты напрямую
// (работает даже если коллайдер шины перекрывает ступицу!)
Collider[] nearCols = Physics.OverlapSphere(hitPoint, 0.35f, interactableLayer, QueryTriggerInteraction.Collide);
foreach (var c in nearCols)
{
CarPart part = c.GetComponentInParent<CarPart>();
if (part != null && part.TotalBoltsCount > 0 && part.State == PartState.Installed)
{
foreach (WheelBolt b in part.GetComponentsInChildren<WheelBolt>(true))
{
if (b == null || !b.IsAvailableForAim) continue;
CheckWheel(c.GetComponentInParent<CarPart>());
Vector3 boltPos = b.WorldBoltCenter;
float distToRay = Vector3.Cross(ray.direction, boltPos - ray.origin).magnitude;
if (distToRay < minRayDist)
{
minRayDist = distToRay;
closest = b;
}
}
}
// На случай если луч попал прямо в коллайдер самого болта
WheelBolt directBolt = c.GetComponent<WheelBolt>();
if (directBolt != null && directBolt.IsAvailableForAim)
if (directBolt != null && directBolt.IsAvailableForAim && (directBolt.IsTightened || hasWrench))
{
float distToRay = Vector3.Cross(ray.direction, directBolt.WorldBoltCenter - ray.origin).magnitude;
if (distToRay < minRayDist)
@@ -288,7 +354,7 @@ public class PlayerInteractor : MonoBehaviour
return closest;
}
private string BuildPrompt(VehicleInteraction vehicle, IInteractable interactable, CarPart part)
{
string partPrompt = (interactable != null && !(interactable is VehicleInteraction))