Teach me RayCasting!

Hey Guys! Very curious about the following native:

I know this has to do with RayCasting which has to do with drawing a line from point A to ponint B, HOWEVER, unfortunately, I’m unsure how to leverage this. Eventually, I would like a ped to drive a straight line, and if any deviation happens that ped would correct and line back up on that line, but I’m having trouble figuring out the ins and outs of this native. I’d love some help from someone who’s used this previously!


I think you might rather want TASK_VEHICLE_FOLLOW_WAYPOINT_RECORDING - Cfx.re Docs with a custom set of waypoint recording files, or maybe there’s still an equivalent of scripted waypoints as well.

deviation means any obstacle in front of the car? because you can just use a task and the ped will turn and go to the objective, anyway:

raycast is used with https://docs.fivem.net/natives/?_0x3D87450E15D98694 so you can just put the StartShapeTestLosProbe inside it, then use the values returned by GetShapeTestResult:

local status, hitornot, endcoords,normal, entity=GetShapeTestResult(StartShapeTestLosProbe(startcoord.x,startcoord.y,startcoord.z,endcoord.x,endcoord.y,endcoord.z,-1,yourcar,4)

StartShapeTestRay arguments are start and end coords, -1 is flag unused, yourcar is the entity to ignore and 4 a common flag

inside a loop you can use a if, if hitornot is true: obstacle ahead, also you can check what type of obstacle/if it is terrain or not with the returned or not entity

Correct me if I’m wrong, but aren’t those like suuuper static? Like there’s no way to make like a conditional tree (like: If car gets hit by other car, head to other coordinates) or something like that? E.g. like an interrupt as the waypoint recording is playing? If so I’ll do some research on waypoint recordings.

Okay, I may not have been honest with you regarding my intentions. For that I apologize. I can sometimes be sensitve of my plans and who sees them before releasing them. It’s a plane AI script. Using TaskPlaneMission and TaskDriveToCoord, I’m able to get the ped to fly the plane, but just not accurately. I’m okay with the steep banks, however, between the time we get to the runway, and the final approach, the ped JUST cares about the end-coordinate using TaskPlaneMission, and not lining up to get to that coord.

THIS is why I’m trying to raycast. Just want to figure out how to get more accuracy within my AI script.

Anyways, do you think it’s possible?

Ah, planes are a bit different in most ways; shape test natives work to get if an obstacle is in the way yes, if you want to reassign tasks based on that it could work.

but would it work if I tried using the raycast beam as a path to fly along? If not, then I’ll have to try using a recording, OR I’ll have to try something different!