Topic: rayHit (In layman's terms)

Here is the example in the wiki:

Example2, test the intersection with an object :
   object = getObject("object")
   
   function onSceneUpdate()
       start = {0, 0, 0}
       end = {100, 0, 0}
       point = rayHit(start, end, object)
       if point then
           print(point)
       end
   end

Here is my understanding of what the rayHit() function does, and how it can be used:

The rayHit() function shoots out a beam from a start position to an end position.
If the beam collides with something it returns the location of the object. If it doesn't it returns "nil"

Here is where my understanding breaks down. Is the "point" variable a point in 3d space or is it a boolean?
For instance, if there IS a collision then does the rayHit() function return TRUE and therefore make the point variable equale to TRUE?

How can it be both if it is?

And what is the "object" variable really doing? Is it making the rayHit() function detect a specific object? If so, what does it do with that object? give it's location? If it does give it's location, is it making the "point" variable equal to it's location (a 3d point in space)?

I need to understand this in layman's terms (as dumb as you can make it, yet clear).

Re: rayHit (In layman's terms)

"point" returns the 3D coordinates of the location where the collision happen between the ray and an object with physics..
If you want to use it as a boolean, just check "if point then ..."

"object" returns the actual object hit by the ray, so yes it detects the specific object being hit.
You can get the position of this object using "if object then getPosition(object) end".
You can get its name using getName(object) function.

NB: object is returned even if you didn't declare it previously with the getObject() function.

Last edited by com3D (2013-10-13 06:08:25)