Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. void DistAB()
  2. {
  3. //the X, Y coordinates of the points that the lines intersect with
  4. var PtAx = GameObject.Find("A").transform.position.x;
  5. var PtAy = GameObject.Find("A").transform.position.z;
  6. var PtBx = GameObject.Find("B").transform.position.x;
  7. var PtBy = GameObject.Find("B").transform.position.z;
  8. var PtCx = GameObject.Find("C").transform.position.x;
  9. var PtCy = GameObject.Find("C").transform.position.z;
  10. var PtDx = GameObject.Find("D").transform.position.x;
  11. var PtDy = GameObject.Find("D").transform.position.z;
  12. var PtEx = GameObject.Find("E").transform.position.x;
  13. var PtEy = GameObject.Find("E").transform.position.z;
  14. var PtFx = GameObject.Find("F").transform.position.x;
  15. var PtFy = GameObject.Find("F").transform.position.z;
  16. var PtGx = GameObject.Find("G").transform.position.x;
  17. var PtGy = GameObject.Find("G").transform.position.z;
  18.  
  19.  
  20. //TrialManager.lastposition = player position (either their X or Y coordinate, as needed)
  21. var lineAB = (Mathf.Abs((PtBy - PtAy) * (TrialManager.lastPosition.x)) - ((PtBx - PtAx) * (TrialManager.lastPosition.z)) + ((PtBx * PtAy) - (PtBy * PtAx))) /
  22. (Mathf.Sqrt((Mathf.Pow((PtBy - PtAy), 2)) + (Mathf.Pow((PtBx - PtAx), 2))));
  23.  
  24.  
  25. var lineBC = (Mathf.Abs((PtCy - PtBy) * (TrialManager.lastPosition.x)) - ((PtCx - PtBx) * (TrialManager.lastPosition.z)) + ((PtCx * PtBy) - (PtCy * PtBx))) /
  26. (Mathf.Sqrt((Mathf.Pow((PtCy - PtBy), 2)) + (Mathf.Pow((PtCx - PtBx), 2))));
  27.  
  28. //find and return smallest distance from 'route' segments
  29. var myMin = Mathf.Min(lineAB, lineBC);
  30. Debug.Log(myMin);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement