Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions functions/World/examples/processLineAgainstMesh-1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
addEventHandler("onClientRender", root,
function()
local camX, camY, camZ, targetX, targetY, targetZ = getCameraMatrix()
local dirX = targetX - camX
local dirY = targetY - camY
local dirZ = targetZ - camZ

local endX = camX + dirX * 100
local endY = camY + dirY * 100
local endZ = camZ + dirZ * 100

for _, vehicle in ipairs(getElementsByType("vehicle")) do
local hit, _, _, textureName = processLineAgainstMesh(
vehicle,
camX, camY, camZ,
endX, endY, endZ
)

if hit and textureName then
print("Hit texture: " .. textureName)
break
end
end
end
)
7 changes: 6 additions & 1 deletion functions/World/processLineAgainstMesh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ shared:
- name: endZ
type: float
description: MISSING_PARAM_DESC
examples: []
examples:
- path: examples/processLineAgainstMesh-1.lua
description: This example prints the name of the texture hit by the player's crosshair
on any vehicle in the world. It uses processLineAgainstMesh to check
for collisions between a line from the camera to a point in front of it and the meshes of vehicles.
side: client
returns:
values:
- type: bool
Expand Down
Loading