Search the Community
Showing results for tags 'processlineofsight'.
-
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 function drawLineFromHead(ped, angle) if isElement(ped) and getElementType(ped) == "ped" then local pedX, pedY, pedZ = getElementPosition(ped) local pedRotation = getPedRotation(ped) + angle local pedRotationRad = math.rad(pedRotation) 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) drawLineFromHead(ped, -45) drawLineFromHead(ped, 0) drawLineFromHead(ped, 45) end setPedControlState(testPed, "forwards", true) -- Main Loop addEventHandler("onClientRender", root, function() drawLinesForPerspective(testPed) local x, y, z = getElementPosition(getLocalPlayer()) end)