Jump to content

*Adaptive Cruise Control* Help please


jkub

Recommended Posts

Posted

I have made a cruise control script a long time ago and I was working to upgrade it today to be able to process lines of sight in front of it to be able to adjust speed to not hit anything. volvo_adaptive-cruise-control_01a-25pc_p2003-2148.jpg

I understand it would be tactical to use processLineOfSight or isLineOfSightClear but the problem with that is I don't know how to calculate distance in front of a vehicle to get the end points.

My major weakness is applying advanced math (I barely even know) and trigonometric functions in order to calculate space in front of the vehicle.

Here is some code.

function cruiseOn() 
    if isPedInVehicle ( getLocalPlayer() ) then 
        if getVehicleController ( getPedOccupiedVehicle ( getLocalPlayer() ) ) == getLocalPlayer() then 
            local vehX, vehY, vehZ = getElementVelocity ( getPedOccupiedVehicle ( getLocalPlayer() ) ) 
            local vx, vy, vz = getElementPosition ( getPedOccupiedVehicle ( getLocalPlayer() ) ) 
            local vrot, vrot, vrot = getVehicleRotation ( getPedOccupiedVehicle ( getLocalPlayer() ) ) 
            local realSpeed = ( vehX^2 + vehY^2 + vehZ^2 ) ^ ( 0.5 ) 
            local sX, sY = guiGetScreenSize() 
            local pX, pY = guiGetPosition ( panel, false ) 
            local sizeX, sizeY = guiGetSize ( panel, false ) 
            ---- 
            dxDrawImage ( pX, pY, sizeX, sizeY, "images/cruiseOn.png", 0, 0, 0, tocolor ( 255, 255, 255, 255 ), true  )  
            --dxDrawLine3D ( vx, vy, vz, endx, endy, endz, tocolor ( 255, 0, 0, 100 ), 4, true, 0 ) 
            if realSpeed < cruise_Speed then 
                setControlState ( "accelerate", true ) 
            else 
                setControlState ( "accelerate", false ) 
            end 
        end 
    else 
        removeEventHandler ( "onClientRender", getRootElement(), cruiseOn ) 
        cruise = nil 
        cruise_Speed = nil 
        setControlState ( "accelerate", false ) 
        if cruise == nil then 
            cruiseControlStatus = nil 
        end 
    end 
end 

crysis-02.png
Posted
function getPositionRelatedToVehicle(theVeh, meters) 
    local xx, yy, zz = getElementPosition(theVeh) 
    local rx, ry, rot = getElementRotation(theVeh) 
    local lx = xx + math.sin (math.rad(-rot)) * meters 
    local ly = yy + math.cos (math.rad(-rot)) * meters 
    return lx,ly 
end  

notice this will fail when car is driving uphill (rotated) - point will be underground, and isLineOfSightClear will fail.

this is best thing i can give you anyway

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

Thanks greatly varez :)

Aside from the z problem I can't currently seem to get to the mta wiki for the arguments for lineOfSightClear and the others.

Ill try this out.

crysis-02.png
Posted

I have a couple more problems lol.

1. It does not detect vehicles

2. Whenever the ray does detect an obstruction in the way, after deaccelerating and braking, I cannot disengage the brake...

I used setControlState to disable the accel and enable the brake when something is detected but everytime after stopped, I have to manually press the brake or handbrake to release it. I have had this problem setControlState before.

crysis-02.png
Posted

post current script..

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...