Optional argument ignore_positions for LuaSurface::find_non_colliding_position
Posted: Sun Apr 16, 2023 2:29 pm
What?
Please add an optional argument ignore_positions (array of positions) that will be ignored by LuaSurface::find_non_colliding_position! If the argument is nil, return the first non-colliding position found, otherwise return the first non-colliding position which is not listed in ignore_positions.Use case
In Autodrive, I use LuaSurface::request_path to get a path from a vehicle's position to the position selected by a player. If no path is found, I look for a non-colliding position in a certain radius around the vehicle, teleport it there, and request a new path from the vehicle's current position to the destination. Repeat if necessary.This usually works, but I've got into a situation where the vehicle is teleported continuously between the same two positions because it can't find a path from neither: I'm not sure how find_non_colliding_position works, but I suppose it is like this:
The function is called as surface.find_non_colliding_position(name, center, radius, precision). Starting from the angle given by vehicle.orientation, a circle with the radius "precision" is searched (either clockwise or anticlockwise). If no suitable position has been found, the radius is extended by "precision" until either a non-colliding position could be found or the maximum defined by "radius" has been searched.