Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
refactor(client): raycast flags and los check
Browse files Browse the repository at this point in the history
Some entities aren't hit by raycasts when interacting with the world,
which is why we alternate flags. When using flag 30, check line-of-sight
to ensure it's not being hit through a wall.
Reduced raycast length from 10000 to 16, and collider to 7.

Didn't notice anything break from this, but needs confirmation.
  • Loading branch information
thelindat committed Aug 4, 2022
1 parent cdcb599 commit 30afa03
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ local function RaycastCamera(flag, playerCoords)
if not playerCoords then playerCoords = GetEntityCoords(playerPed) end

local rayPos, rayDir = ScreenPositionToCameraRay()
local destination = rayPos + 10000 * rayDir
local rayHandle = StartShapeTestLosProbe(rayPos.x, rayPos.y, rayPos.z, destination.x, destination.y, destination.z, flag or -1, playerPed, 0)
local destination = rayPos + 16 * rayDir
local rayHandle = StartShapeTestLosProbe(rayPos.x, rayPos.y, rayPos.z, destination.x, destination.y, destination.z, flag or -1, playerPed, 7)

while true do
local result, _, endCoords, _, entityHit = GetShapeTestResult(rayHandle)

if result ~= 1 then
local distance = playerCoords and #(playerCoords - endCoords)

if flag == 30 and entityHit then
entityHit = HasEntityClearLosToEntity(entityHit, playerPed, 7) and entityHit
end

return endCoords, distance, entityHit, entityHit and GetEntityType(entityHit) or 0
end

Expand Down Expand Up @@ -306,7 +311,7 @@ local function EnableTarget()
until not targetActive
end)

local flag
local flag = 30

while targetActive do
local sleep = 0
Expand Down Expand Up @@ -337,7 +342,7 @@ local function EnableTarget()
elseif entityType == 2 then
local closestBone, _, closestBoneName = CheckBones(coords, entity, Bones.Vehicle)
local data = Bones.Options[closestBoneName]

if data and next(data) and closestBone then
SetupOptions(data, entity, distance)
if next(nuiData) then
Expand Down

0 comments on commit 30afa03

Please sign in to comment.