Более менее пашет
This commit is contained in:
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))
|
||||
|
||||
@@ -6,14 +6,37 @@ public class PlayerLook : MonoBehaviour
|
||||
[SerializeField] private float mouseSensitivity = 150f;
|
||||
[SerializeField] private Transform playerBody;
|
||||
|
||||
[Header("Zoom Settings")]
|
||||
[SerializeField] private KeyCode zoomKey = KeyCode.Z;
|
||||
[SerializeField] private bool allowRightClickZoomWhenHandsEmpty = true;
|
||||
[SerializeField] private float zoomFov = 28f;
|
||||
[SerializeField] private float minZoomFov = 18f;
|
||||
[SerializeField] private float maxZoomFov = 45f;
|
||||
[SerializeField] private float zoomSpeed = 12f;
|
||||
[SerializeField] private float scrollZoomStep = 4f;
|
||||
[Range(0.15f, 1f)]
|
||||
[SerializeField] private float zoomSensitivityMultiplier = 0.45f;
|
||||
|
||||
private float xRotation = 0f;
|
||||
private Camera cam;
|
||||
private PlayerHands hands;
|
||||
private float defaultFov = 60f;
|
||||
private float currentZoomFov;
|
||||
|
||||
public float Sensitivity => mouseSensitivity;
|
||||
public bool IsZooming { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (playerBody == null) playerBody = transform.parent != null ? transform.parent : transform;
|
||||
mouseSensitivity = PlayerPrefs.GetFloat("perekup_sensitivity", mouseSensitivity);
|
||||
|
||||
cam = GetComponent<Camera>();
|
||||
if (cam == null) cam = GetComponentInChildren<Camera>();
|
||||
if (cam != null) defaultFov = cam.fieldOfView;
|
||||
|
||||
currentZoomFov = Mathf.Clamp(zoomFov, minZoomFov, maxZoomFov);
|
||||
hands = GetComponentInParent<PlayerHands>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -22,6 +45,34 @@ public class PlayerLook : MonoBehaviour
|
||||
GameInputLock.ApplyCursor();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (cam == null) return;
|
||||
|
||||
if (hands == null) hands = GetComponentInParent<PlayerHands>();
|
||||
|
||||
bool canUseZoom = !GameInputLock.IsLocked && VehicleInteraction.Current == null;
|
||||
bool handsEmpty = hands == null || !hands.IsHoldingAnything;
|
||||
|
||||
bool keyHeld = Input.GetKey(zoomKey);
|
||||
bool rmbHeld = allowRightClickZoomWhenHandsEmpty && handsEmpty && Input.GetMouseButton(1);
|
||||
|
||||
IsZooming = canUseZoom && (keyHeld || rmbHeld);
|
||||
|
||||
// Колёсико мыши во время зума подстраивает приближение
|
||||
if (IsZooming)
|
||||
{
|
||||
float scroll = Input.mouseScrollDelta.y;
|
||||
if (Mathf.Abs(scroll) > 0.01f)
|
||||
{
|
||||
currentZoomFov = Mathf.Clamp(currentZoomFov - scroll * scrollZoomStep, minZoomFov, maxZoomFov);
|
||||
}
|
||||
}
|
||||
|
||||
float targetFov = IsZooming ? currentZoomFov : defaultFov;
|
||||
cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, targetFov, Time.deltaTime * zoomSpeed);
|
||||
}
|
||||
|
||||
public void SetSensitivity(float value)
|
||||
{
|
||||
mouseSensitivity = Mathf.Clamp(value, 20f, 600f);
|
||||
@@ -37,8 +88,16 @@ public class PlayerLook : MonoBehaviour
|
||||
|
||||
public void ProcessLook(Vector2 input)
|
||||
{
|
||||
float mouseX = input.x * mouseSensitivity * Time.deltaTime;
|
||||
float mouseY = input.y * mouseSensitivity * Time.deltaTime;
|
||||
// Плавно снижаем чувствительность при приближении, чтобы удобно целиться в мелкие детали
|
||||
float sensMult = 1f;
|
||||
if (cam != null && defaultFov > minZoomFov + 1f)
|
||||
{
|
||||
float zoomT = Mathf.InverseLerp(defaultFov, minZoomFov, cam.fieldOfView);
|
||||
sensMult = Mathf.Lerp(1f, zoomSensitivityMultiplier, zoomT);
|
||||
}
|
||||
|
||||
float mouseX = input.x * mouseSensitivity * sensMult * Time.deltaTime;
|
||||
float mouseY = input.y * mouseSensitivity * sensMult * Time.deltaTime;
|
||||
|
||||
// Расчет наклона камеры с ограничением, чтобы нельзя было сломать шею
|
||||
xRotation -= mouseY;
|
||||
@@ -50,4 +109,4 @@ public class PlayerLook : MonoBehaviour
|
||||
// Вращаем само тело игрока (влево/вправо)
|
||||
playerBody.Rotate(Vector3.up * mouseX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,7 +678,7 @@ public class PlayerToolManager : MonoBehaviour
|
||||
case ToolType.Sander: return visuals.Sand(dt / sandTime);
|
||||
case ToolType.SprayCan:
|
||||
if (visuals.Stage == RepairStage.Sanded) return visuals.PaintRepair(dt / paintTime);
|
||||
return visuals.Recolor(sprayPaintColor);
|
||||
return false;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
@@ -693,7 +693,7 @@ public class PlayerToolManager : MonoBehaviour
|
||||
case RepairStage.Sanded: return tool == ToolType.SprayCan;
|
||||
case RepairStage.Healthy:
|
||||
case RepairStage.Repaired:
|
||||
return tool == ToolType.SprayCan; // Баллончик может перекрашивать
|
||||
return false; // Баллончик может перекрашивать
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user