RayHit

From MaratisWiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Launch a ray and returns the result of the test : the intersection point or nil<br> ''note : only detects objects with physics collision enabled'' Example1, test the interse...")
 
m
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Launch a ray and returns the result of the test : the intersection point or nil<br>
+
{{lua-function|rayHit|start, end}}
''note : only detects objects with physics collision enabled''
+
  
 +
Launch a ray and returns the result of the test, the intersection point or nil and optionally the object. Note that only detects objects with physics collision enabled.
  
Example1, test the intersection with the full scene :
+
{{lua-function-param|start|ray start}}
 +
{{lua-function-param|end|ray end}}
 +
 
 +
point, object = rayHit(start, end)
 +
 
 +
Or.
 +
 
 +
point = rayHit(start, end, object)
 +
 
 +
'''Example 1:''' Test the intersection with the full scene.
  
 
     function onSceneUpdate()
 
     function onSceneUpdate()
 
         start = {0, 0, 0}
 
         start = {0, 0, 0}
 
         end = {100, 0, 0}
 
         end = {100, 0, 0}
         point = rayHit(start, end)
+
         point, object = rayHit(start, end)
 
         if point then
 
         if point then
             print(point)
+
             print(point) -- print point
 +
            print(getName(object)) -- print object name
 
         end
 
         end
 
     end
 
     end
  
Example2, test the intersection with an object :
+
'''Example 2:''' Test the intersection with an object.
  
 
     object = getObject("object")
 
     object = getObject("object")
 
+
   
 
     function onSceneUpdate()
 
     function onSceneUpdate()
 
         start = {0, 0, 0}
 
         start = {0, 0, 0}
Line 26: Line 36:
 
         end
 
         end
 
     end
 
     end
 +
 +
[[Category:Lua scripting]]
 +
[[Category:Lua function]]
 +
[[Category:Physics]]

Latest revision as of 00:28, 9 February 2014

rayHit(start, end)

Launch a ray and returns the result of the test, the intersection point or nil and optionally the object. Note that only detects objects with physics collision enabled.

  • start : ray start
  • end : ray end
point, object = rayHit(start, end)

Or.

point = rayHit(start, end, object)

Example 1: Test the intersection with the full scene.

   function onSceneUpdate()
       start = {0, 0, 0}
       end = {100, 0, 0}
       point, object = rayHit(start, end)
       if point then
           print(point) -- print point
           print(getName(object)) -- print object name
       end
   end

Example 2: 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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox