how do collision masks work in request_path
Posted: Wed May 31, 2023 1:38 am
So I have the following code that I've been trying to make work for a few days now. Essentially, when the move(x,y) function is called it automatically gets a path with request_path then has the player walk along that path. The code to handle the walking is not shown here but it works fine, the main problem is that I can't for the life of me figure out how to make request_path avoid water. I feel that I've tried a million combinations of collision maps and bounding boxes, but without fail request_path will go over water if it gets the chance.
Does anyone know how to solve this? There was also a recent forum post about a similar topic but the posted solution was not actually a solution.
Does anyone know how to solve this? There was also a recent forum post about a similar topic but the posted solution was not actually a solution.
Code: Select all
function move(x,y)
local surface = game.get_surface("nauvis")
local character = game.get_player(1).character
local position = {x = x, y = y}
local collision_mask = {
"player-layer",
"train-layer",
"consider-tile-transitions",
"water-tile",
"object-layer"
}
--
t = character.bounding_box
--probable reason for pathing over water is collision masks.
--follow this link for collision masks https://wiki.factorio.com/Types/CollisionMask
pos = character.position
--local bbox ={{pos.x - 0.5, pos.y - 0.5},{pos.x + 0.5, pos.y + 0.5}}
--local bbox2 = {{-0.1,-0.1},{0.1,0.1}}
surface.request_path{
bounding_box = t,
collision_mask = collision_mask,
start = character.position,
goal = position,
force = "player",
path_resolution_modifier = 0
}
end