#need example on pathfinding
1 messages · Page 1 of 1 (latest)
Here's what I got, but doesn't find a path to the target:
```control.lua
---@param goal MapPosition
local function findPathToTarget(goal)
local player = game.players[1]
if not player.character then return end
player.surface.request_path {
bounding_box = player.character.prototype.collision_box,
collision_mask = player.character.prototype.collision_mask,
start = player.position,
goal = goal,
force = player.force,
radius = 4,
pathfind_flags = {
cache = false,
low_priority = false,
allow_failed_to_start = true,
allow_failed_to_finish = true
},
id = player.index
}
end
It always returns the `event` without a `path` property.
does it error or not return anything
it returns the event without erroring, but the event has no path indicating it didn't found a path.
eg: {"name":134,"tick":3603,"id":1,"try_again_later":false}
do you have a listener for on_script_path_request_finished yet?
yep, that is where I'm getting the event without the path
it returns nil if pathfinding failed according to the API
how can I debug this?
I mean, there is no further details on why it failed
The scenario I'm trying is:
- load the game
- get player position
- get nearest iron ore position
- check if iron ore was found
- request a path from player to iron ore
what does your control.lua file look like
Here it is and the other modules required by it.
I've pushed my drafts here for ease of navigation:
I've also tried to find a path to a known unblocked point { x = 10, y = 10 } because I thought collision would be the problem, but the event still comes without a path and so collision is not the thing I guess...
I think I got it.
I believe I need only to call player.surface.find_non_colliding_position for the positions passed to player.surface.request_path...
But I don't fully understand why, since testing without any obstacles the path is still not calculated.
not sure, feels a little weird