Снятие колес работает, покраска тоже более менее. Физика просто говно щяс
This commit is contained in:
1 parent
d4c84b10df
commit
2ce853999d
67 files changed
+155919
-1996
No files matched your search
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
public class PlayerInteractor : MonoBehaviour
|
||||
{
|
||||
[Header("Настройки луча")]
|
||||
[SerializeField] private float interactRange = 3f;
|
||||
[SerializeField] private float interactRange = 3.2f;
|
||||
[SerializeField] private LayerMask interactableLayer;
|
||||
|
||||
[Header("Клавиши управления")]
|
||||
@@ -15,11 +15,12 @@ public class PlayerInteractor : MonoBehaviour
|
||||
[SerializeField] private UIManager uiManager;
|
||||
|
||||
private CarPart lastHoveredPart;
|
||||
private PlayerHands cachedHands;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (uiManager == null)
|
||||
uiManager = FindAnyObjectByType<UIManager>();
|
||||
if (uiManager == null) uiManager = FindAnyObjectByType<UIManager>();
|
||||
cachedHands = FindAnyObjectByType<PlayerHands>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@@ -30,34 +31,40 @@ public class PlayerInteractor : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (CarJack.ActiveJackInHand != null)
|
||||
{
|
||||
uiManager?.ShowPrompt(CarJack.ActiveJackInHand.GetPlacementPrompt());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CarJack.ActiveJackInHand != null) return;
|
||||
|
||||
Ray ray = new Ray(transform.position, transform.forward);
|
||||
GameObject playerRoot = transform.root.gameObject;
|
||||
|
||||
// 0. Если в руках деталь — проверяем все зоны установки по лучу (чтобы кузов не перекрывал зону колеса!)
|
||||
if (cachedHands == null) cachedHands = FindAnyObjectByType<PlayerHands>();
|
||||
if (cachedHands != null && cachedHands.IsHolding)
|
||||
{
|
||||
RaycastHit[] allHits = Physics.RaycastAll(ray, interactRange, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
foreach (var h in allHits)
|
||||
{
|
||||
CarPartMountZone zone = h.collider.GetComponentInParent<CarPartMountZone>();
|
||||
if (zone != null)
|
||||
{
|
||||
ResetProgressTargets();
|
||||
string zPrompt = zone.GetPrompt();
|
||||
if (!string.IsNullOrEmpty(zPrompt))
|
||||
uiManager?.ShowPrompt(zPrompt);
|
||||
else
|
||||
uiManager?.HidePrompt();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, interactRange, interactableLayer, QueryTriggerInteraction.Collide))
|
||||
{
|
||||
GameObject playerRoot = transform.root.gameObject;
|
||||
|
||||
// 1. ПРИОРИТЕТ БОЛТАМ: проверяем, не целимся ли мы в колесный болт (даже сквозь коллайдер шины)
|
||||
WheelBolt bolt = hit.collider.GetComponent<WheelBolt>();
|
||||
if (bolt == null)
|
||||
{
|
||||
Collider[] nearCols = Physics.OverlapSphere(hit.point, 0.06f, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
foreach (var c in nearCols)
|
||||
{
|
||||
bolt = c.GetComponent<WheelBolt>();
|
||||
if (bolt != null) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bolt != null)
|
||||
// 1. ТОЧНЫЙ ПОИСК БЛИЖАЙШЕГО К ПРИЦЕЛУ БОЛТА
|
||||
WheelBolt bestBolt = FindClosestBoltToRay(ray, hit.point);
|
||||
if (bestBolt != null)
|
||||
{
|
||||
ResetProgressTargets();
|
||||
string boltPrompt = bolt.GetPrompt();
|
||||
string boltPrompt = bestBolt.GetPrompt();
|
||||
if (!string.IsNullOrEmpty(boltPrompt))
|
||||
uiManager?.ShowPrompt(boltPrompt);
|
||||
else
|
||||
@@ -65,7 +72,28 @@ public class PlayerInteractor : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Обычные объекты, детали и авто
|
||||
// 2. ПРИОРИТЕТ ДОМКРАТУ ПОД ПОРОГОМ
|
||||
CarJack jack = hit.collider.GetComponentInParent<CarJack>();
|
||||
if (jack == null)
|
||||
{
|
||||
Collider[] nearJackCols = Physics.OverlapSphere(hit.point, 0.22f, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
foreach (var c in nearJackCols)
|
||||
{
|
||||
jack = c.GetComponentInParent<CarJack>();
|
||||
if (jack != null) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jack != null)
|
||||
{
|
||||
ResetProgressTargets();
|
||||
uiManager?.ShowPrompt(jack.GetPrompt());
|
||||
if (Input.GetKeyDown(primaryKey))
|
||||
jack.Interact(playerRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. ОБЫЧНЫЕ ДЕТАЛИ И АВТОМОБИЛЬ
|
||||
IInteractable interactable = hit.collider.GetComponentInParent<IInteractable>();
|
||||
VehicleInteraction vehicle = hit.collider.GetComponentInParent<VehicleInteraction>();
|
||||
CarPart part = hit.collider.GetComponentInParent<CarPart>();
|
||||
@@ -79,21 +107,13 @@ public class PlayerInteractor : MonoBehaviour
|
||||
|
||||
if (interactable != null || vehicle != null)
|
||||
{
|
||||
// Посадка в авто (F)
|
||||
if (Input.GetKeyDown(enterVehicleKey) && vehicle != null)
|
||||
{
|
||||
vehicle.Interact(playerRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
// Зона обратной установки детали (обрабатывается внутри CarPartMountZone)
|
||||
if (mountZone != null)
|
||||
{
|
||||
if (Input.GetKeyDown(primaryKey))
|
||||
mountZone.Interact(playerRoot);
|
||||
}
|
||||
// Работа с деталью (снятие / открытие / подбор с земли)
|
||||
else if (part != null)
|
||||
if (mountZone == null && part != null)
|
||||
{
|
||||
if (part.State == PartState.Dropped)
|
||||
{
|
||||
@@ -103,7 +123,6 @@ public class PlayerInteractor : MonoBehaviour
|
||||
else if (part.State == PartState.Installed)
|
||||
{
|
||||
bool hasAnimator = part.GetComponent<CarPartAnimator>() != null;
|
||||
|
||||
if (hasAnimator)
|
||||
{
|
||||
if (Input.GetKeyDown(primaryKey))
|
||||
@@ -123,7 +142,7 @@ public class PlayerInteractor : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (interactable != null && Input.GetKeyDown(primaryKey))
|
||||
else if (mountZone == null && interactable != null && Input.GetKeyDown(primaryKey))
|
||||
{
|
||||
interactable.Interact(playerRoot);
|
||||
}
|
||||
@@ -142,6 +161,29 @@ public class PlayerInteractor : MonoBehaviour
|
||||
uiManager?.HidePrompt();
|
||||
}
|
||||
|
||||
private WheelBolt FindClosestBoltToRay(Ray ray, Vector3 hitPoint)
|
||||
{
|
||||
Collider[] cols = Physics.OverlapSphere(hitPoint, 0.08f, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
WheelBolt closest = null;
|
||||
float minRayDist = 0.045f; // Максимальное отклонение от точки прицела (4.5 см)
|
||||
|
||||
foreach (var c in cols)
|
||||
{
|
||||
WheelBolt b = c.GetComponent<WheelBolt>();
|
||||
if (b == null || !b.IsAvailableForAim) continue;
|
||||
|
||||
// Считаем расстояние от центра конкретного болта до линии взгляда игрока
|
||||
Vector3 boltPos = b.WorldBoltCenter;
|
||||
float distToRay = Vector3.Cross(ray.direction, boltPos - ray.origin).magnitude;
|
||||
if (distToRay < minRayDist)
|
||||
{
|
||||
minRayDist = distToRay;
|
||||
closest = b;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
private string BuildPrompt(VehicleInteraction vehicle, IInteractable interactable)
|
||||
{
|
||||
string partPrompt = (interactable != null && !(interactable is VehicleInteraction))
|
||||
|
||||
Reference in new issue
Block a user