jkub Posted October 8, 2010 Share Posted October 8, 2010 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. 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 Link to comment
dzek (varez) Posted October 8, 2010 Share Posted October 8, 2010 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 Link to comment
jkub Posted October 9, 2010 Author Share Posted October 9, 2010 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. Link to comment
jkub Posted October 9, 2010 Author Share Posted October 9, 2010 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. Link to comment
dzek (varez) Posted October 9, 2010 Share Posted October 9, 2010 post current script.. Link to comment
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