Система со сменой колес дорабавтываю. Есть задатки системы объявлений и встречи с продавцом
This commit is contained in:
1 parent
2ce853999d
commit
27ad7eac11
25 files changed
+37130
-34404
No files matched your search
@@ -92,6 +92,26 @@ public class PlayerInteractor : MonoBehaviour
|
||||
jack.Interact(playerRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
WheelBrickSupport bricks = hit.collider.GetComponentInParent<WheelBrickSupport>();
|
||||
if (bricks == null)
|
||||
{
|
||||
Collider[] nearBrickCols = Physics.OverlapSphere(hit.point, 0.22f, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
foreach (var c in nearBrickCols)
|
||||
{
|
||||
bricks = c.GetComponentInParent<WheelBrickSupport>();
|
||||
if (bricks != null) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bricks != null)
|
||||
{
|
||||
ResetProgressTargets();
|
||||
uiManager?.ShowPrompt(bricks.GetPrompt());
|
||||
if (Input.GetKeyDown(primaryKey))
|
||||
bricks.Interact(playerRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. ОБЫЧНЫЕ ДЕТАЛИ И АВТОМОБИЛЬ
|
||||
IInteractable interactable = hit.collider.GetComponentInParent<IInteractable>();
|
||||
@@ -163,24 +183,44 @@ public class PlayerInteractor : MonoBehaviour
|
||||
|
||||
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 см)
|
||||
float minRayDist = 0.085f; // Радиус захвата точки прицела (8.5 см вокруг луча)
|
||||
|
||||
foreach (var c in cols)
|
||||
// 1. Ищем колесо в радиусе попадания луча и проверяем ВСЕ его дочерние болты напрямую
|
||||
// (работает даже если коллайдер шины перекрывает ступицу!)
|
||||
Collider[] nearCols = Physics.OverlapSphere(hitPoint, 0.35f, interactableLayer, QueryTriggerInteraction.Collide);
|
||||
foreach (var c in nearCols)
|
||||
{
|
||||
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)
|
||||
CarPart part = c.GetComponentInParent<CarPart>();
|
||||
if (part != null && part.TotalBoltsCount > 0 && part.State == PartState.Installed)
|
||||
{
|
||||
minRayDist = distToRay;
|
||||
closest = b;
|
||||
foreach (WheelBolt b in part.GetComponentsInChildren<WheelBolt>(true))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// На случай если луч попал прямо в коллайдер самого болта
|
||||
WheelBolt directBolt = c.GetComponent<WheelBolt>();
|
||||
if (directBolt != null && directBolt.IsAvailableForAim)
|
||||
{
|
||||
float distToRay = Vector3.Cross(ray.direction, directBolt.WorldBoltCenter - ray.origin).magnitude;
|
||||
if (distToRay < minRayDist)
|
||||
{
|
||||
minRayDist = distToRay;
|
||||
closest = directBolt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,10 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
private void HandleCrouch()
|
||||
{
|
||||
isCrouching = Input.GetKey(crouchKey);
|
||||
if (Input.GetKeyDown(crouchKey))
|
||||
{
|
||||
isCrouching = !isCrouching;
|
||||
}
|
||||
|
||||
float targetHeight = isCrouching ? crouchHeight : standHeight;
|
||||
float currentDelta = initialHeight - targetHeight;
|
||||
|
||||
Reference in new issue
Block a user