Most Efficient Method for Steering for Vehicle AI

Hi Unity Community!

Any tutorial regarding vehicle AI gives the following code for getting the steering magnitude (-1 to 1) to the next waypoint:

Vector3 pos = transform.InverseTransformPoint(nextWaypoint.position);
steerMagnitude = pos.x / pos.magnitude;

But since this involves the Sqrt operation, is there a more efficient method? Because I plan on having about minimum 50 vehicles in the scene at a time. But that can even increase to 100 - 200 vehicles. Or is the Sqrt operation fast enough for mobile devices to cope with 200 vehicles using this code each FixedUpdate? I also have other code like OA, etc.

What’s your fixed timestep? I think the default is 0.02, but there’s no way when I’m driving I adjust by steering 50 times a second… if you need to keep the timestep that high for other calculations, then don’t recalculate the steering magnitude in every FixedUpdate() - put it in a coroutine, say, that runs less frequently.