How can I do make pathfinding based on collision masks?

Hi, How can I do make pathfinding based on collision masks and not on the obstacle objects sprites?
I’m making a topdown 2D Game, therefore longer objects like trees and towers have a way smaller collision masks than there actual object size. it would be great if the pathfinding objects would watch out for the collision masks of obstacles and not for there actual size.
I also tried «Navigation mesh pathfinding (experimental)», but I was not able to find a solution.

Is there another way apart from making a separate collision map for all pathfinding objects?
This would get unnecessary complicated.

Try putting all your trees and stuff in one object folder and the path finding object in one
and then in events do

But how is this effecting the pathfinding? it still will avoid the whole object and not the collision mask. no?

no it will only avoid collisions

I tried it. It’s unfortunately not working, the pathfinding is still taking the whole objects into account :confused:

Standard pathfinding will always take the whole AABB square of the object into account for pathfinding obstacles.

You can get more precise with the navmesh pathfinding extension in the main extension list, though.

The only way I can think of doing it is by using a seperate hidden smaller object as the tree’s pathfinding obstacle. The tree itself wouldn’t have the behavior. You can place it manually or with a for each object using the tree’ bounding box bottom. Minus the height of the hidden hit box depending on where the points on the hidden object are.

I agree sometimes the actual hit box would be useful. You could add a suggestion for a precision style toggle. So, you could switch between the 2 methods. It would probably greatly increase the processing time need to calculate a path.

I tried the extension, but was not able to find a collision mask option. do you where I can set it to collision mask?

I also thought about seeting the collision mask as a separate object, but it’s kind of my last resort -.- as I have a lot of different objects and things get really complicated. Let’s see if someone has a even more elegant solution.

1 Like

By default it is using the hitbox. You set how closely it can match the hitbox (Collision mask rasterization) in your scene properties:

Here’s the navmesh drawn (The only collision mask obstacle is the chest, currently a square)

Here’s the navmesh if I’ve made the collision mask a triangle for the chest.

The smaller you make the cell size, the more precise it will get, but the more CPU intensive it will get.

1 Like

Thank you! This really helped, know it works :slight_smile:

1 Like