R3d.Body:raycast

From GiderosMobile
Revision as of 22:40, 18 December 2025 by MoKaLux (talk | contribs)

Available since: Gideros 2019.10
Class: R3d.Body

Description

Performs a ray cast on a single body.

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

You can perform ray casting against a single specific rigid body of the world.

Parameters

sx: (number) the starting position of the raycast on the x axis
sy: (number) the starting position of the raycast on the y axis
sz: (number) the starting position of the raycast on the z axis
ex: (number) the ending position of the raycast on the x axis
ey: (number) the ending position of the raycast on the y axis
ez: (number) the ending position of the raycast on the z axis

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.body: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