Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to occlude NavigationPolygon set in TileSet at runtime #3821

Closed
TotCac opened this issue Feb 24, 2016 · 44 comments
Closed

Need to occlude NavigationPolygon set in TileSet at runtime #3821

TotCac opened this issue Feb 24, 2016 · 44 comments

Comments

@TotCac
Copy link

TotCac commented Feb 24, 2016

NavigationPolygon can be added to a Tileset to mark a tile to be used by Navigation2d to find a path.
While building your Tilemap, each tile have static data of navigation to be considered by pathfinding.

Problem: If you an extra layer of object that have to be avoided by Navigation2d pathfinding, how can you do?

Is it possible to have this improvment to 2d pathfinding?

@akien-mga
Copy link
Member

I can confirm the need for something like this, unless I'm misusing Navigation2D.

In DynaDungeons, I had tried using Navigation2D (not committed) for pathfinding, but my problem is that I use two tilemaps:

  • One for ground and wall tiles, which have NavigationPolygons to make them either allowed or not for pathfinding (e.g. wall is not allowed, ground is allowed).
  • One for "obstacles" that can be destroyed and thus reveal the ground tile behind them. Typically they are not allowed for pathfinding, but the ground tile behind them is.

With the implementation I had tried, the "allowed" status of the ground tile would take precedence over the "not allowed" status of the obstacle, thus pathfinding would ignore all obstacles.

@jackmakesthings
Copy link
Contributor

Yesss. This would be an extremely good thing to have, I've been wrestling with the same problem @akien-mga described above.

@ProbDenis
Copy link
Contributor

Yes, having some kind of "NavigationOccluder" object would be extremely useful.

@Anarchid
Copy link
Contributor

Having a way to punch holes into navmeshes would be prim, too :P

@Zylann
Copy link
Contributor

Zylann commented Mar 21, 2016

I have the same issue as akien-mga, and I can even have non-tile objects on top of it, that need to be avoided as well. Actually, in some cases it would be easier to build navigation only with occluders instead of nav. polys.

@akien-mga
Copy link
Member

Given how popular this issue is, I'll make sure it's fixed sometime before 2.1 is released :)

@PixelWizzard
Copy link

That would be great!

@genete
Copy link

genete commented Jun 15, 2016

I also need that for my games.
Currently the Navigation2D only takes in consideration the first NavigationPolygon found in the children list. If I have two NavigationPolygon as children and change the position of them, then the Navigation2D consider the first of its children.
It would be great to have this:

  1. Change Navigation2D to consider all the NavigationPolygon children's the result of a boolean combination of all them.
  2. Add one new parameter to the NavigationPolygon to make one boolean operation with the next NavigationPolygon in the children list
  3. Add one new parameter to the NavigationPolygon node to enable or disable its effect.
  4. As said, new navigation occluder. I imagine this would be a bit difficult to implement if the occluder object is not a children of the Navigation2D

With 1) and 2) would be very easy to create moving walls or opening doors. With 3) it would be great to make bodies to do not allow mutual crossing if they are occluding the path.

I have one question:
@TotCac : When you said: "While building your Tilemap, each tile have static data of navigation to be considered by pathfinding." What are you referring to? Is that documented anywhere?
Thanks!

@kakoeimon
Copy link

kakoeimon commented Jun 15, 2016

I think this is in the TODO list but not in the 2.1 as it looks like.
By the way it's called Detour / Recast.
Recast is for creating the navamesh from the polygons of the a 3d model (this is a technique introduced in 3d)
and Detour is the way to navigate on the navigation mesh.
Right now we have only Detour in Godot, a tool for creating NavMesh for 2D and a way to import a 3D navmesh created by the Recast in Blender for example.
We do not have obstacle avoidance and for this reason we do not have the ability to block passages of the navigation mesh, we also we do not have crowd control and for this reason agents eventually get in line when they want to get to the same location.

Edit: Sorry my mistake. This is in the todo list for 2.1
https://trello.com/c/vfEeGOIc/35-local-obstacle-avoidance-in-navigationpoly-mesh

@TotCac
Copy link
Author

TotCac commented Jun 15, 2016

Don't know if this trello is really used by developpers

@TotCac
Copy link
Author

TotCac commented Jun 15, 2016

@kakoeimon when you build your tileset, you define a navigation polygon for each tile. Then, if you set a tilemap as a children of a Navigation2D, each tile will be linked to your navigation2d, and you build a full level of navigation. I said static data because you can't modify it at runtime as it's a tile information. Check this: https://www.youtube.com/watch?v=S-zEA_Ce1mk

@batmanasb
Copy link

To add to this, you can actually use the "set_cell()" in the Tilemap node to switch cells with a NavigationPolygon to cells without them. Which is a way to cut off paths for doors and other roadblocks.

@kakoeimon
Copy link

@batmanasb You are right. Changing the tile from a tile with navigation polygon to a tile without navigation polygon updates the navigation mesh and blocks passages.
@TotCac so to solve your problem you can create a tilemap without graphics but with two blocks

  1. with a NavigationPolygonInstance
  2. with StaticBody2D
    Then make this "transparent" tilemap to take the position of the tiles from another tilemap (the one with the graphics for walls and floors) and use "set_cell()" to change the tiles when ever you want to put somewhere an "obstacle" without changing the graphics.

By the way @reduz reports his progress in Trello.

@TotCac
Copy link
Author

TotCac commented Jun 16, 2016

@kakoeimon It's exactly what I am doing here https://www.youtube.com/watch?v=ThYeRtSqeBU, while adding some wall at runtime, i update a navigation tilemap which is only a navigationpolygoninstance and a staticbody. The problem is for "dynamic" object as car as you can see in video.

edit: my mistake @kakoeimon, hint of tilemap navigation2d what no for you but to @genete :)

@kakoeimon
Copy link

@TotCac Yep, that's why we need obstacle avoidance.

@akien-mga
Copy link
Member

Given how popular this issue is, I'll make sure it's fixed sometime before 2.1 is released :)

I've tried... But it's not critical for the imminent 2.1, so moving to the next milestone.

@akien-mga akien-mga modified the milestones: 2.2, 2.1 Jul 27, 2016
@TotCac
Copy link
Author

TotCac commented Oct 11, 2016

As 2.2 is cancelled, any chance having this in 3.0?

@Zylann
Copy link
Contributor

Zylann commented Oct 11, 2016

This Q&A question could be related: https://godotengine.org/qa/8757/2d-navigation-weighted-tiles-for-difficult-terrain
It also makes sense when you know the AStar class does supports avoidance through "difficulty". Could be implemented by painting the vertices of the navmesh with a custom vertex attribute?

@bojidar-bg
Copy link
Contributor

Bump, which version would include this? 😃

@plucian
Copy link

plucian commented Feb 7, 2017

2.1.2, that'd be great -> 2.1.3

@ProbDenis
Copy link
Contributor

Any chance for this in 3.0 or 3.1? Would be incredibly useful.

@TotCac
Copy link
Author

TotCac commented Jul 20, 2017

I think they should freeze 3.0 and stop adding feature because release get delayed and delayed.
Maybe for a 3.1 I hope

@akien-mga akien-mga modified the milestones: 2.2, 3.1 Sep 18, 2017
@seanfy
Copy link

seanfy commented Mar 7, 2018

When implementing this, would it be possible to give Tilemap node an option to make the whole tilemap navigable by default?

In some cases putting tiles or objects later that blocks your npcs or player from walking through is more natural than painting walkable areas for them.

@tengkuizdihar
Copy link

mfw this issue still open after 2 years

@plucian
Copy link

plucian commented Oct 3, 2018

how would this be different from just removing a tile from the path ? Or put a tile that does not a have a navigation polygon attached to it..

@TotCac
Copy link
Author

TotCac commented Oct 3, 2018

Because obstacle can be bigger than a tile
https://media.giphy.com/media/pHYeMPoUJmFavWbbMM/giphy.gif

@plucian
Copy link

plucian commented Oct 3, 2018

that's not an issue. add as many tiles without nav pol to have a very big obstacle. Also it does not matter the size of the obstacle (could a different object not necessarily a tile), what matters is the break in the nav. path.

@tengkuizdihar
Copy link

I'm bumping this issue so that someone that's good enough to implement this. Btw, they also have a lengthy explanation of the algorithm being used and what not. Please dev, do implement this. I'm afraid I'm not good enough to even understand it. Thank you.

@Zireael07
Copy link
Contributor

@balenol: Godot already is making use of a polygon clipping library named triangle. I am not sure if triangle is exposed to scripting, though?

@tengkuizdihar
Copy link

@Zireael07 I didn't know that. Maybe the only thing this "good enough than I am"-person should do, is to expose that library to the polygon2D object? I mean, does it have the NOT operation (i'm talking about boolean operation on polygon here) so that we could occlude the navmesh somehow? That would be awesome.

@TotCac
Copy link
Author

TotCac commented Oct 25, 2018

I'd already open an issue to expose Clipper library to GDScript, as it's a part of engine external library aldeay #22275.

But, it's not for computing at real time, and should not be used for our needs of new NavigationServer :)
It's on the dev roadmap, we just have to wait for now

@akien-mga akien-mga modified the milestones: 3.1, 3.2 Dec 14, 2018
@PabloNeirotti
Copy link

Not sure what use cases you'll be aiming to cover in the end. But if I could have a Navigation2D with many NavigationPolygonInstance inside and have them all get added together, that'd be super neat.

@tengkuizdihar
Copy link

@PabloNeirotti you do have the ability to do that right now. As long as the corners from each polygon is overlapping, godot will try to solve it. I've tried it with about 10000 instance before and it lag like hell. The clipper implementation is pretty useful because now instead of many instance with overlapping corners, you have one big polygon instance.

@Jeto143
Copy link

Jeto143 commented Apr 20, 2019

+1 on the NavigationOccluder suggestion, that would actually be perfect. Occluders would take precedence over polygons, and a tilemap would ideally also have an option to be fully navigable by default (as also suggested).

@Xrayez
Copy link
Contributor

Xrayez commented May 17, 2019

I think this could be solved with Clipper internally but I'm completely nebulous to path finding and navigation, though I'll give an idea. 😆

If I understand correctly, NavigationPolygon is used as a child of Navigation2D to define walkable areas to find a path. NavigationOccluder would then negate any walkable areas. This could be done just like in CSG nodes in 3D, having UNION for NavigationPolygon and SUBSTRACTION operation defined for NavigationOccluder. The order of nodes could determine how the overall navigation is morphed, and even having ability to disable/enable such nodes by turning their visibility and being able to locally transform navigation polygons based on nodes transform.

@TotCac
Copy link
Author

TotCac commented May 23, 2019

Hello friends,

More than 3 years now that we ask for something to help us.
This is not the solution for collision avoidance, but may be a good workaround for some of you.

Polygon operations on 2D (merge, xor...) and offseting has been merged into master branch 👍

Will have a try into this soon!

@tengkuizdihar
Copy link

@TotCac OH YEAAAAAAAAAAAAAAAAAAAH

@TotCac
Copy link
Author

TotCac commented May 23, 2019

Congrats to @Xrayez juste above

@Xrayez
Copy link
Contributor

Xrayez commented May 23, 2019

Thanks, I've exposed these methods in such a way that it would be applied to plenty of use cases I believe.

I can't really help here until I actually need navigation features in my project to truly understand the use case, maybe some fellows can implement this in the core some day (wait another 3 years? 😅).

@Abstract-Everything
Copy link
Contributor

Polygon operations on 2D (merge, xor...) and offseting has been merged into master branch +1

How are these operations exposed?

@Xrayez
Copy link
Contributor

Xrayez commented May 25, 2019

@J-Camilleri they are available in Geometry singleton, see #28987. It's pretty elemental so these could be used universally and applied to fix this issue I believe (either via scripting or within engine).

@tengkuizdihar
Copy link

@Xrayez definitely. This is definitely helpful. Now I could just make a big/segmented navigation polygon and then clip it off bits by bits when loading. Thank you.

@ToxicCrack
Copy link

If anyone still has the problem with multiple tilemaps, here is a solution i came up with:
https://github.com/ToxicCrack/godot-tilemap-navigation

@akien-mga akien-mga removed this from the 3.2 milestone Nov 11, 2019
@Calinou
Copy link
Member

Calinou commented Jun 9, 2020

Dynamic collision avoidance has been implemented in #34776, closing.

@Calinou Calinou closed this as completed Jun 9, 2020
@Calinou Calinou added this to the 4.0 milestone Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests