1 using System.Collections;
2 using System.Collections.Generic;
9 [RequireComponent(typeof(Collider))]
14 List<Collider> colliders =
new List<Collider>();
20 if (!col) col = GetComponent<Collider>();
21 if (!GrabPoint) GrabPoint = GetComponentInParent<AVR_BasicGrabProvider>().grabPoint;
26 return col.ClosestPoint(pos);
32 if (IsOnline && !IsOwner)
return;
34 if (other.GetType() == typeof(MeshCollider) && !((MeshCollider)other).convex)
return;
35 if (!colliders.Contains(other)) colliders.Add(other);
41 if (IsOnline && !IsOwner)
return;
43 if (colliders.Contains(other)) colliders.Remove(other);
47 float smallest_dist = float.PositiveInfinity;
48 Collider smallest_coll = null;
49 Vector3 closest_point = Vector3.zero;
51 for (
int i = 0; i < colliders.Count; i++)
55 colliders.RemoveAt(i);
60 Collider c = colliders[i];
61 Vector3 p = c.ClosestPoint(GrabPoint.position);
62 if (Vector3.Distance(p, GrabPoint.position) < smallest_dist)
64 smallest_dist = Vector3.Distance(p, GrabPoint.position);
70 if(smallest_coll==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);
85 if(Vector3.Distance(GrabPoint.position, node.transform.position) < node.override_radius) {
86 location =
new GrabLocation(grb, closest_point, smallest_dist, node);
92 location =
new GrabLocation(grb, closest_point, smallest_dist, smallest_coll);
Retrieves an AVR_Grabbable from a given volume (convex collider). The object closest to the given Gra...
List< AVR_GrabNode > grabNodes
List of GrabNodes that are attatched to this object
Represents an (attempted) grab at a given location of an object.
Represents a grabbable object.
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
override Vector3 closestPoint(Vector3 pos)
override bool getGrabLocation(out GrabLocation location)
void OnTriggerExit(Collider other)
void OnTriggerEnter(Collider other)
Class to retrieve a Grabbable object from a location, volume or similar.