diff --git a/functions/World/examples/processLineAgainstMesh-1.lua b/functions/World/examples/processLineAgainstMesh-1.lua new file mode 100644 index 00000000..aed15048 --- /dev/null +++ b/functions/World/examples/processLineAgainstMesh-1.lua @@ -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 +) \ No newline at end of file diff --git a/functions/World/processLineAgainstMesh.yaml b/functions/World/processLineAgainstMesh.yaml index 4f03df02..b83c6d0d 100644 --- a/functions/World/processLineAgainstMesh.yaml +++ b/functions/World/processLineAgainstMesh.yaml @@ -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