Difference between revisions of "R3d.Fixture:raycast"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 1: Line 1:
 +
__NOTOC__
 
'''Available since:''' Gideros 2019.10<br/>
 
'''Available since:''' Gideros 2019.10<br/>
 
'''Class:''' [[R3d.Fixture]]<br/>
 
'''Class:''' [[R3d.Fixture]]<br/>
  
 
=== Description ===
 
=== Description ===
Performs a ray cast on the fixture.
+
Performs a ray cast on a single fixture.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
r3d.Fixture:raycast(sx,sy,sz,ex,ey,ez)
+
(table) = r3d.Fixture:raycast(sx,sy,sz,ex,ey,ez)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
'''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 ===
 
=== Parameters ===
'''sx''': (number) the starting position of the raycast on the X axis<br/>
+
'''sx''': (number) the starting position of the raycast on the x axis in world-space coordinates<br/>
'''sy''': (number) the starting position of the raycast on the Y axis<br/>
+
'''sy''': (number) the starting position of the raycast on the y axis in world-space coordinates<br/>
'''sz''': (number) the starting position of the raycast on the Z axis<br/>
+
'''sz''': (number) the starting position of the raycast on the z axis in world-space coordinates<br/>
'''ex''': (number) the ending position of the raycast on the X axis<br/>
+
'''ex''': (number) the ending position of the raycast on the x axis in world-space coordinates<br/>
'''ey''': (number) the ending position of the raycast on the Y axis<br/>
+
'''ey''': (number) the ending position of the raycast on the y axis in world-space coordinates<br/>
'''ez''': (number) the ending position of the raycast on the Z axis<br/>
+
'''ez''': (number) the ending position of the raycast on the z axis in world-space coordinates<br/>
 +
 
 +
=== Return values ===
 +
'''Returns''' (table) a table containing the raycast information:
 +
*fixture: (table)
 +
*body: (table)
 +
*worldNormal: (table)
 +
*hitFraction: (number)
 +
*worldPoint: (table)
 +
*triangleIndex: (number)
  
 
=== Example ===
 
=== Example ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 +
local player1rc = player1.fixture:raycast(1,2,10, 1,2,-20)
 +
if player1rc then
 +
-- fixture: (table)
 +
-- body: (table)
 +
-- worldNormal: (table)
 +
-- hitFraction: (number)
 +
-- worldPoint: (table)
 +
-- triangleIndex: (number)
 +
print(player1rc.fixture, player1rc.body.id)
 +
print(player1rc.worldNormal[1], player1rc.worldNormal[2], player1rc.worldNormal[3])
 +
print(player1rc.hitFraction)
 +
print(player1rc.worldPoint[1], player1rc.worldPoint[2], player1rc.worldPoint[3])
 +
print("****************************")
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
{{R3d.Fixture}}
 
{{R3d.Fixture}}

Latest revision as of 01:35, 19 December 2025

Available since: Gideros 2019.10
Class: R3d.Fixture

Description

Performs a ray cast on a single fixture.

(table) = r3d.Fixture:raycast(sx,sy,sz,ex,ey,ez)

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 on the x axis in world-space coordinates
sy: (number) the starting position of the raycast on the y axis in world-space coordinates
sz: (number) the starting position of the raycast on the z axis in world-space coordinates
ex: (number) the ending position of the raycast on the x axis in world-space coordinates
ey: (number) the ending position of the raycast on the y axis in world-space coordinates
ez: (number) the ending position of the raycast on the z axis in world-space coordinates

Return values

Returns (table) a table containing the raycast information:

  • fixture: (table)
  • body: (table)
  • worldNormal: (table)
  • hitFraction: (number)
  • worldPoint: (table)
  • triangleIndex: (number)

Example

local player1rc = player1.fixture:raycast(1,2,10, 1,2,-20)
if player1rc then
	-- fixture: (table)
	-- body: (table)
	-- worldNormal: (table)
	-- hitFraction: (number)
	-- worldPoint: (table)
	-- triangleIndex: (number)
	print(player1rc.fixture, player1rc.body.id)
	print(player1rc.worldNormal[1], player1rc.worldNormal[2], player1rc.worldNormal[3])
	print(player1rc.hitFraction)
	print(player1rc.worldPoint[1], player1rc.worldPoint[2], player1rc.worldPoint[3])
	print("****************************")
end