Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gMe = getLocalPlayer()
- local gLastTick = nil
- local TUBE_RADIUS = 5
- local TOWARD_LINE_FACTOR = 0.001
- local ALONG_LINE_FACTOR = 0.0003
- local gLines = {
- { vec(0, 0, 3), vec(0, 10, 10) }
- }
- addEventHandler('onClientResourceStart', resourceRoot,
- function()
- for i,line in ipairs(gLines) do
- line.length = (line[2] - line[1]):len()
- line.dir = (line[2] - line[1]):normalize()
- end
- end
- )
- addEventHandler('onClientRender', root,
- function()
- local vehicle = getPedOccupiedVehicle(gMe)
- if not vehicle then
- return
- end
- local newTick = getTickCount()
- if not gLastTick then
- gLastTick = newTick - 50
- end
- local interval = newTick - gLastTick
- gLastTick = newTick
- local vPos = vec(getElementPosition(vehicle))
- for i,line in ipairs(gLines) do
- dxDrawLine3D(line[1][1], line[1][2], line[1][3], line[2][1], line[2][2], line[2][3], tocolor(255, 0, 0))
- local distAlongLine = (vPos - line[1]) * line.dir
- if distAlongLine >= 0 and distAlongLine <= line.length then
- local carToLine = line.dir:cross(line.dir:cross(vPos - line[1]))
- local distToLine = carToLine:len()
- if distToLine <= TUBE_RADIUS then
- local vVel = vec(getElementVelocity(vehicle))
- vVel = vVel + (carToLine / distToLine) * (distToLine / TUBE_RADIUS)*TOWARD_LINE_FACTOR*interval
- vVel = vVel + line.dir * ALONG_LINE_FACTOR*interval
- setElementVelocity(vehicle, unpack(vVel))
- break
- end
- end
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement