VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
override bool AVR.Phys.AVR_GrabbableVolumeFinder.getGrabLocation ( out GrabLocation  location)
inlinevirtual

Implements AVR.Phys.AVR_GrabbableFinder.

Definition at line 46 of file AVR_GrabbableVolumeFinder.cs.

46  {
47  float smallest_dist = float.PositiveInfinity;
48  Collider smallest_coll = null;
49  Vector3 closest_point = Vector3.zero;
50 
51  for (int i = 0; i < colliders.Count; i++)
52  {
53  if (!colliders[i])
54  {
55  colliders.RemoveAt(i);
56  i--;
57  continue;
58  }
59 
60  Collider c = colliders[i];
61  Vector3 p = c.ClosestPoint(GrabPoint.position);
62  if (Vector3.Distance(p, GrabPoint.position) < smallest_dist)
63  {
64  smallest_dist = Vector3.Distance(p, GrabPoint.position);
65  smallest_coll = c;
66  closest_point = p;
67  }
68  }
69 
70  if(smallest_coll==null) {
71  location = null;
72  return false;
73  }
74 
75  AVR_Grabbable grb = smallest_coll.GetComponentInParent<AVR_Grabbable>();
76 
77  if(grb==null) {
78  AVR.Core.AVR_DevConsole.cwarn("Attempted to grab a collider without an AVR_Grabbable component. Either 1) attatch an AVR_Grabbable to the respective object, or 2), disable collisions between the volumefinder and the given object.", this);
79  location = null;
80  return false;
81  }
82 
83  if(grb.grabNodes!=null) {
84  foreach(var node in grb.grabNodes) {
85  if(Vector3.Distance(GrabPoint.position, node.transform.position) < node.override_radius) {
86  location = new GrabLocation(grb, closest_point, smallest_dist, node);
87  return true;
88  }
89  }
90  }
91 
92  location = new GrabLocation(grb, closest_point, smallest_dist, smallest_coll);
93  return true;
94  }