how do collision masks work in request_path

Place to get help with not working mods / modding interface.
Post Reply
rawls
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue May 30, 2023 2:46 am
Contact:

how do collision masks work in request_path

Post by rawls »

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.

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

rawls
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue May 30, 2023 2:46 am
Contact:

Re: how do collision masks work in request_path

Post by rawls »

Update, so now I'm just confused on the collision mask hierarchy. Making a bounding box centered at 0,0 and only utilizing the "water-tile" collision mask means it's suddenly not pathing on water, but also it won't path over things like belts which it should
Last edited by rawls on Wed May 31, 2023 6:18 pm, edited 1 time in total.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2252
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: how do collision masks work in request_path

Post by boskid »

By having bounding box centered at {0,0} and passing a water-tile collision mask it should not path over water anymore since that layer collides with water tile. Most likely what you say is not what your code does so please share your currently not working code piece to get accurate answers.

As for the collision layers, collision masks system has some limitations built in, one of them being that any 2 objects that share a collision layer will collide, even if they are 2 entities both colliding water-tile layer. If you want a path that is suitable for a character, you should use character's collision mask which i think consists of "player" and "train" layers. Those layers guarantee the path will not go over water (since water tile collides with player layer) but it will be able to go over transport belts as they do not have a shared layer here.

Post Reply

Return to “Modding help”