Commit 5ccafe44 authored by Danial KordModanlou's avatar Danial KordModanlou

closest distance system updated

parent 27042952
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<Path>.vs</Path> <Path>.vs</Path>
<Path>Library</Path> <Path>Library</Path>
<Path>Logs</Path> <Path>Logs</Path>
<Path>Temp</Path>
<Path>obj</Path> <Path>obj</Path>
</explicitExcludes> </explicitExcludes>
</component> </component>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -11,13 +11,45 @@ public class Wall : MonoBehaviour ...@@ -11,13 +11,45 @@ public class Wall : MonoBehaviour
void Start() void Start()
{ {
coll = this.GetComponent<MeshCollider>(); coll = this.GetComponent<MeshCollider>();
DataSaver.sideDistance = distanceToCar; //DataSaver.sideDistance = distanceToCar;
DataSaver.sideDistance = newMethod;
} }
public Vector3 distanceToCar(Vector3 car) public Vector3 distanceToCar(Vector3 car)
{ {
Vector3 closestPoint = coll.ClosestPointOnBounds(car); car = transform.InverseTransformPoint(car);
Debug.Log(closestPoint);
Debug.Log(GetComponent<MeshCollider>().name);
Vector3 closestPoint = GetComponent<MeshCollider>().ClosestPointOnBounds(car);
Debug.Log("--> "+ car +" " +transform.TransformPoint(closestPoint));
return closestPoint; return closestPoint;
} }
public Vector3 newMethod(Vector3 point)
{
point = transform.InverseTransformPoint(point);
Mesh mesh = GetComponent<MeshFilter>().mesh;
float minDistanceSqr = Mathf.Infinity;
Vector3 nearestVertex = Vector3.zero;
// scan all vertices to find nearest
foreach (Vector3 vertex in mesh.vertices)
{
Vector3 diff = point-vertex;
float distSqr = diff.sqrMagnitude;
if (distSqr < minDistanceSqr)
{
minDistanceSqr = distSqr;
nearestVertex = vertex;
}
}
// convert nearest vertex back to world space
Debug.Log("--> "+ point +" " +minDistanceSqr + " " + transform.TransformPoint(nearestVertex));
return transform.TransformPoint(nearestVertex);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment