mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-03 06:49:22 +00:00
i have no fucking clue
This commit is contained in:
parent
730ff58adc
commit
f783fe612d
21 changed files with 496 additions and 49 deletions
30
InteractionTest/ColliderTest/LineColliderTest.cs
Normal file
30
InteractionTest/ColliderTest/LineColliderTest.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using UnityEngine;
|
||||
|
||||
public static class SphereBetweenLinesHelper
|
||||
{
|
||||
public static bool IsSphereBetweenLines(Vector3 lineStart, Vector3 lineEnd, Vector3 sphereCenter, float sphereRadius)
|
||||
{
|
||||
// Calculate the closest point on the line to the sphere's center
|
||||
Vector3 closestPointOnLine = GetClosestPointOnLine(lineStart, lineEnd, sphereCenter);
|
||||
|
||||
// Calculate the distance between the sphere's center and the closest point on the line
|
||||
float distanceToLine = Vector3.Distance(sphereCenter, closestPointOnLine);
|
||||
|
||||
// Check if the sphere is between the lines
|
||||
return distanceToLine < sphereRadius;
|
||||
}
|
||||
|
||||
// Get the closest point on a line to a given point
|
||||
private static Vector3 GetClosestPointOnLine(Vector3 lineStart, Vector3 lineEnd, Vector3 point)
|
||||
{
|
||||
Vector3 lineDirection = (lineEnd - lineStart).normalized;
|
||||
float closestPointDistance = Vector3.Dot((point - lineStart), lineDirection);
|
||||
return lineStart + (closestPointDistance * lineDirection);
|
||||
}
|
||||
|
||||
public static bool IsPointWithinDistance(Vector3 position, Vector3 point, float distance)
|
||||
{
|
||||
float distanceToPosition = Vector3.Distance(position, point);
|
||||
return distanceToPosition <= distance;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue