#runtime navigation2d mesh calculation?

8 messages · Page 1 of 1 (latest)

quick jungle
#

probably not as simple as I'm hoping but want to for a defined chunk get all colliders and cut them out of the navigation area, I was hoping doing something like this would work:

var x = Geometry2D.MergePolygons(a.Polygon,b.Polygon);
x =Geometry2D.ClipPolygons(big.Polygon,x);

this doesn't work as x becomes a PackedVector2Array since the answer to the union question can be a poligon with holes, meaning i cant just pass that to clip as the clip function takes a single polygon.

I'm aware I'm basically asking for Boolean subtraction of a 2d mesh but not sure how it would be implemented using the Godot toys and not building from scratch.

what is the correct way to achieve this, bonus points for if the answer is fast enough to do run time for a reasonable area.

eternal dove
#

This is rather tricky because the Geometry2D class has problems doing more than one polygon like this at the same time. But I dont think you need to struggle doing this manually anymore. The 2D navigation mesh baking PR was merged 1-2 days ago into Godot master and should be part of the next Godot 4.2 snapshot. https://github.com/godotengine/godot/pull/80796

GitHub

Adds 2D navigation mesh baking for NavigationRegion2D and NavigationServer2D.
Slight compatibility breaking on the baking process of the NavigationPolygon, see info further below.

Supersedes #7072...

quick jungle
#

Baking implying not runtime?

eternal dove
#

no, navmesh baking can be used both in the editor or at runtime. The only real limitation is that if your scene is very large you better do it in a background thread at runtime to not freeze your main thread.

quick jungle
#

Are multiple smaller areas preferred to one large area in terms of recalculating meshes

eternal dove
#

What matters for performance is the total amount of points and edges. The size not really.

quick jungle
#

Thanks swapped to the latest Dev branch and it's working great! Follow up question what would be a sensible way to path away from something, doesn't have to be a perfect solution just wanted to have the chicken run away from the player and not directly into a corner when chased.

Also is there a correct way to get the poligons/mesh an agent is currently on? I'm not sure I get where to use the RIDs that are returned from the functions that look like they would

eternal dove
#

You can get the current NavigationRegion from the owner of a polygon. The NavigationAgent or NavigationPathQueryResult can collect path meta data, so you can get information e.g. what is the owner (e.g. what node) of a path point. Else you can query the server to get the closest owner for a position. An owner in server / engine context is an ObjectID number because Nodes are only a concept of the SceneTree. If you want to get the object, e.g. the node, behind an ObjectID number you can use the function instance_from_id()