Jayceon Posted April 22, 2017 Posted April 22, 2017 (edited) Hello. I tried to get the crossroad and crossroad angles but i don't know how. I'm using the vehicle nodes path and i have small code to get road nodes angle but it get all nodes and i'm only need the crossroads. The current code: function createGPSRoute(x, y, x2, y2) local occupiedVehicle = getPedOccupiedVehicle(localPlayer) local vehicleX, vehicleY, vehicleZ = getElementPosition(occupiedVehicle) if occupiedVehicle then local startNode = findNodePosition(x, y) local endNode = findNodePosition(x2, y2) local gpsRoute = getNodePath(startNode, endNode) if #gpsRoute ~= 0 then local gpsWaypoints = {} for k, v in pairs(gpsRoute) do local nextNode = gpsRoute[k + 1] if nextNode then local roadRotation = (360 - math.deg(math.atan2((nextNode.x - vehicleX), (nextNode.y - vehicleY)))) % 360 local _, _, vehicleRotation = getElementRotation(occupiedVehicle) local vehicleRotation = vehicleRotation or 0 local roadAngle = (roadRotation - vehicleRotation) % 360 local distance = getDistanceBetweenPoints3D(vehicleX, vehicleY, vehicleZ, nextNode.x, nextNode.y, nextNode.z) local accuracy = distance < 7 and 20 or 6 if roadAngle > -accuracy and roadAngle < accuracy then table.insert(gpsWaypoints, {nextNode.neighbours, "forward", distance}) elseif roadAngle <= 360 and roadAngle >= 180 then table.insert(gpsWaypoints, {nextNode.neighbours, "right", distance}) elseif roadAngle >= 0 and roadAngle <= 180 then table.insert(gpsWaypoints, {nextNode.neighbours, "left", distance}) end end end outputConsole(inspect(gpsWaypoints)) -- debug to console end end end Thanks the replies. Edited April 22, 2017 by Jayceon
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now