First, we create an array of GameObject
s (any object that inherents a Transform
) for anything we want to be detected by Raycast
s.
Then, we pass this array of created GameObject
s into the constructor for the HeirarchicalVolumeManager
object to create a Bounding Volume Hierarchy (BVH).
This builds a BVH and organizes all of the passed GameObjects into the tree. Now searching for raycast interception is a lot less costly (before searching would take O(n), but now its averaged at O(log(n))).
To cast a ray, we first create a new Raycast
object and
then provide the start point and end point of the raycast (in World Coordinates [x,y]).
To check if the raycast has intercepted any objects just call the
update(headNode)
function to get a list of all the
objects it intercepted.
headNode
is simply the HeirarchicalVolumeManager.getHeadNode()
.)
Now we can use this array of intercepted GameObject
s and use them in any way we wish.