Difference between revisions of "R3d.World:raycast"
| Line 24: | Line 24: | ||
=== Example === | === Example === | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
| − | function raycastcallback( | + | function raycastcallback(e) |
-- fixture: table | -- fixture: table | ||
-- body: table | -- body: table | ||
| Line 31: | Line 31: | ||
-- worldPoint: table | -- worldPoint: table | ||
-- triangleIndex: number | -- triangleIndex: number | ||
| − | for k, v in pairs( | + | for k, v in pairs(e.fixture) do |
print("fixture:", k, v) | print("fixture:", k, v) | ||
end | end | ||
| − | print("body id:", | + | print("body id:", e.body.id) |
| − | print("world normal coords:", | + | print("world normal coords:", e.worldNormal[1], e.worldNormal[2], e.worldNormal[3]) |
| − | print("hit fraction:", | + | print("hit fraction:", e.hitFraction) |
| − | print("world point coords:", | + | print("world point coords:", e.worldPoint[1], e.worldPoint[2], e.worldPoint[3]) |
| − | print("triangle index:", | + | print("triangle index:", e.triangleIndex) |
end | end | ||
world:raycast(0, 0, 0, 0, 10, -32, raycastcallback) | world:raycast(0, 0, 0, 0, 10, -32, raycastcallback) | ||
Latest revision as of 23:00, 18 December 2025
Available since: Gideros 2019.10
Class: R3d.World
Description
Performs a ray cast on the world.
r3d.World:raycast(sx,sy,sz,ex,ey,ez,callback[,category])
Ray casting
You can use ReactPhysics3D to test intersection between a ray and the bodies of the world you have created. Ray casting can be performed against multiple bodies, a single body or any collider of a given body. Note that ray casting only works from the outside of the bodies. If the origin of a ray is inside a collision shape, no hit will be reported.
Parameters
sx: (number) the starting position of the raycast in the world x axis
sy: (number) the starting position of the raycast in the world y axis
sz: (number) the starting position of the raycast in the world z axis
ex: (number) the ending position of the raycast in the world x axis
ey: (number) the ending position of the raycast in the world y axis
ez: (number) the ending position of the raycast in the world z axis
callback: (function) the callback function
category: (number) bit mask for collision filtering optional
Example
function raycastcallback(e)
-- fixture: table
-- body: table
-- worldNormal: table
-- hitFraction: number
-- worldPoint: table
-- triangleIndex: number
for k, v in pairs(e.fixture) do
print("fixture:", k, v)
end
print("body id:", e.body.id)
print("world normal coords:", e.worldNormal[1], e.worldNormal[2], e.worldNormal[3])
print("hit fraction:", e.hitFraction)
print("world point coords:", e.worldPoint[1], e.worldPoint[2], e.worldPoint[3])
print("triangle index:", e.triangleIndex)
end
world:raycast(0, 0, 0, 0, 10, -32, raycastcallback)
- R3d.World
- R3d.World.new
- R3d.World:createBallAndSocketJoint
- R3d.World:createBody
- R3d.World:createFixedJoint
- R3d.World:createHingeJoint
- R3d.World:createSliderJoint
- R3d.World:destroyBody
- R3d.World:destroyJoint
- R3d.World:getGravity
- R3d.World:raycast
- R3d.World:setEventListener
- R3d.World:setGravity
- R3d.World:step
- R3d.World:testCollision
- R3d.World:testOverlap