Skip to content

Commit edc93a5

Browse files
author
0d3vq
committed
Add example for processLineAgainstMesh demonstrating texture hit detection
1 parent 53f9043 commit edc93a5

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
addEventHandler("onClientRender", root,
2+
function()
3+
local camX, camY, camZ, targetX, targetY, targetZ = getCameraMatrix()
4+
local dirX = targetX - camX
5+
local dirY = targetY - camY
6+
local dirZ = targetZ - camZ
7+
8+
local endX = camX + dirX * 100
9+
local endY = camY + dirY * 100
10+
local endZ = camZ + dirZ * 100
11+
12+
for _, vehicle in ipairs(getElementsByType("vehicle")) do
13+
local hit, _, _, textureName = processLineAgainstMesh(
14+
vehicle,
15+
camX, camY, camZ,
16+
endX, endY, endZ
17+
)
18+
19+
if hit and textureName then
20+
print("Hit texture: " .. textureName)
21+
break
22+
end
23+
end
24+
end
25+
)

functions/World/processLineAgainstMesh.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ shared:
3434
- name: endZ
3535
type: float
3636
description: MISSING_PARAM_DESC
37-
examples: []
37+
examples:
38+
- path: examples/processLineAgainstMesh-1.lua
39+
description: This example prints the name of the texture hit by the player's crosshair
40+
on any vehicle in the world. It uses processLineAgainstMesh to check
41+
for collisions between a line from the camera to a point in front of it and the meshes of vehicles.
42+
side: client
3843
returns:
3944
values:
4045
- type: bool

0 commit comments

Comments
 (0)