Is Ray Raycast optimize for AI path finding

Hello lads ,

So I’m working on a working on a traffic simulator ND I want to shoot 5 Raycast each for every AI vehicle spawned , this would serve as ai sensor,

Would this affect the performance

how many vehicles do you have?

but in general, on desktop, can shoot thousands of raycasts easily…
theres also batched version

Like 300 vehicles max

i’d test raycast and check profiler how much it costs…

optionally,
do you need to raycast every frame, or it could be delayed to a slower rate?

No it doesn’t always need to be there always, only when ai get close to other vehicles or player, any idea how I can do that

could use triggers (like each vehicle has invisible sphere collider trigger around them),
physics.overlapsphere from script, Coroutine that only runs every x seconds,
Space partitioning (basically only check distances to objects that are nearby within same or neighbor cell), Also can assign suitable physics layers and use layermasks (to only check raycast hits with certain layer).

Or, for each vehicle, could cast forward ray every frame, but other rays only every x frames.
Or, instead of raycasts, attach actual meshes with trigger colliders as “rays” on the vehicles.

but still, i’d try brute force all rays first, and see if that can be made fast enough already.

1 Like

Lovely thansks mate