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

Weird navmesh artefacts #28

Closed
subGlitch opened this issue Jul 25, 2020 · 4 comments
Closed

Weird navmesh artefacts #28

subGlitch opened this issue Jul 25, 2020 · 4 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@subGlitch
Copy link

subGlitch commented Jul 25, 2020

I have weird navmesh artefacts. You can see them in the screenshot. I managed to fix them by adding a quad rotated (90, 0, 0) and referencing it in Use Mesh Prefab setting of the NavMeshSurface2d. I don't understand why this fixed the problem, but somehow it worked.

But for me this solution feels like just a workaround. I think there should be no artefacts in a first place.

P.S.: thanks you very much for such a great tool

artefacts
no artefacts

@h8man h8man self-assigned this Jul 25, 2020
@h8man h8man added the question Further information is requested label Jul 25, 2020
@h8man
Copy link
Owner

h8man commented Jul 25, 2020

Hi,

I see dotted line, and bake setting Default Area - Walkable.
So first NavMeshPlus creates huge box area as walkable, and than carves out unwalkable regions.
I assume that you sprite shape are not complete squares and have some gaps, and those gaps are not carved out.

You can override tile shape by "Use Mesh Prefab", as you do.
Or, if your world is in square tiles, enable "Override by Grid".
Or, better use this scenario https://github.com/h8man/NavMeshPlus/wiki/HOW-TO#baking-a-maze

Also, enable compress bounds, it will increase bake time, but also will delete excessive tiles.

@subGlitch
Copy link
Author

subGlitch commented Jul 25, 2020

I assume that you sprite shape are not complete squares and have some gaps, and those gas are not carved out.

But does it matter? Because I use ColliderType.Grid, not ColliderType.Sprite.

Oh! I've just managed to fix the problem! See my fix in the code below. This is part of NavMeshBuilder2d.CollectTileSources() method. I don't understand why it fixed the problem. It was just a lucky guess. I wonder what was the issue...

else //default to box
{
    var boxsrc = new NavMeshBuildSource();
    boxsrc.transform = Matrix4x4.TRS(Vector3.Scale(tilemap.GetCellCenterWorld(vec3int), builder.overrideVector) - tilemap.layoutGrid.cellGap, tilemap.transform.rotation, tilemap.transform.lossyScale) * tilemap.orientationMatrix * tilemap.GetTransformMatrix(vec3int);
    boxsrc.shape = NavMeshBuildSourceShape.Box;
    // boxsrc.size = size;                          // problem: NavMesh artefacts =(
    boxsrc.size = new Vector3( 1, 1, 0 );           // All good!
    boxsrc.area = area;
    sources.Add(boxsrc);
}

@h8man h8man added the bug Something isn't working label Jul 25, 2020
@h8man
Copy link
Owner

h8man commented Jul 25, 2020

Hi,

Yes, it does matter if you bake Geometry https://github.com/h8man/NavMeshPlus/wiki/HOW-TO#used-geometry
NavMeshPlus does not tolerate tilemaps "ColliderType".
Unity have public API to get mesh form sprite, or mesh from collider, but not mesh from grid cell, or mesh from sprite physics shape. And we need that mesh.

As for code above, I assume there is a bug. If both "Override Grid" and "Use Mesh Prefab" are used, than "size" is overwritten and does not correspond to grid's cell size.
var size = new Vector3(tilemap.layoutGrid.cellSize.x, tilemap.layoutGrid.cellSize.y, 0);
and
if (builder.useMeshPrefab != null) { ... size = builder.useMeshPrefab.transform.localScale;

@subGlitch
Copy link
Author

var size = new Vector3(tilemap.layoutGrid.cellSize.x, tilemap.layoutGrid.cellSize.y, 0);

Yep, this works! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants