# ProcessLineOfSight problem

## Recommended Posts

The problem is that there is a ped that runs straight, and there are also drawn lines that show how the ped is looking. And I would like to make this ped when it notices an obstacle with a given line "processOfLineSight" to paint it red from the green line. But unfortunately when the ped runs and sees an obstacle on the right side, the middle line lights up instead of the one on the right side. It's the same with the rest, the middle line, when it notices something, the left line lights up and so on. Can someone help me with this?

```local direction = 0
local testPed = createPed(0,2480.52344, -1649.07202, 103.77657, direction)
local lineLength = -10
local distanceOfStart = 0

local color = {{255, 0, 0},{0, 255, 0}}
local colorSet = 2

if isElement(ped) and getElementType(ped) == "ped" then
local pedX, pedY, pedZ = getElementPosition(ped)
local pedRotation = getPedRotation(ped) + angle

local lineEndX = pedX + lineLength * math.sin(pedRotationRad)
local lineEndY = pedY - lineLength * math.cos(pedRotationRad)

dxDrawLine3D(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, tocolor(color[colorSet][1], color[colorSet][2], color[colorSet][3]), 2)

local hit = processLineOfSight(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, true, false, false)

if hit then
colorSet = 1
else
colorSet = 2
end
end
end

function drawLinesForPerspective(ped)

end

setPedControlState(testPed, "forwards", true)

-- Main Loop
drawLinesForPerspective(testPed)

local x, y, z = getElementPosition(getLocalPlayer())

end)```

• Moderators
21 hours ago, Xwaw said:

It's the same with the rest, the middle line, when it notices something

Keep it simple:

```local hit = processLineOfSight(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, true, false, false)

local colorSet = hit and 1 or 2

dxDrawLine3D(pedX, pedY, pedZ + distanceOfStart, lineEndX, lineEndY, pedZ+ distanceOfStart, tocolor(color[colorSet][1], color[colorSet][2], color[colorSet][3]), 2)```

## Create an account

Register a new account