-
-
Notifications
You must be signed in to change notification settings - Fork 4
Raycast
selimanac edited this page Oct 7, 2024
·
6 revisions
See: 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 ofresult
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
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. Theresult
table contains aabb_ids and distances. -
count
(uint32) - Count ofresult
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
If you find my Defold Extensions useful for your projects, please consider supporting it.
I'd love to hear about your projects! Please share your released projects that use my native extensions. It would be very motivating for me.