Skip to content

Raycast

selimanac edited this page Oct 7, 2024 · 6 revisions

See: Mask Bits

daabbcc.raycast(group_id, start_x, start_y, end_x, end_y, [mask_bits])

Perform ray casts against the group.

Parameters

  • group_id (uint8) - Group ID
  • start_x (float) - Ray start position X.
  • start_y (float) - Ray start position Y.
  • end_x (float) - Ray end position X.
  • end_y (float) - Ray end position Y.
  • mask_bits (uint64)[optional] - Default is all

Returns

  • result (table) - Table of possible overlapping AABB IDs.
  • count (uint32) - Count of result table.

Example

local group_id = aabb.new_group()

local collision_bits = {
	PLAYER      = 1, 
	ENEMY       = 2, 
	ITEM        = 4,
	ALL         = bit.bnot(0)  -- -1 for all results
}
local mask_bits = bit.bor(collision_bits.ENEMY, collision_bits.ITEM)
local ray_start = vmath.vector3(0, 0, 0)
local ray_end = vmath.vector3(365, 370, 0)

local result, count =  daabbcc.raycast(group_id, start_x, start_y, end_x, end_y, mask_bits)

if result then
	for i = 1, count do
		 print(result[i])
	end
end

daabbcc.raycast_sort(group_id, start_x, start_y, end_x, end_y, [mask_bits])

Perform ray casts against the group. Returns a result table with AABB IDs and distances, ordered from closest to farthest.

Parameters

  • group_id (uint8) - Group ID
  • start_x (float) - Ray start position X.
  • start_y (float) - Ray start position Y.
  • end_x (float) - Ray end position X.
  • end_y (float) - Ray end position Y.
  • mask_bits (uint64)[optional] - Default is all

Returns

  • result (table) - Table of possible overlapping AABBs. The result table contains aabb_ids and distances.
  • count (uint32) - Count of result table.

Example

local group_id = aabb.new_group()

local ray_start = vmath.vector3(0, 0, 0)
local ray_end = vmath.vector3(365, 370, 0)

local result, count =  daabbcc.raycast_sort(group_id, start_x, start_y, end_x, end_y)

if result then
	for i = 1, count do
		 print(result[i])
	end
end


Clone this wiki locally