Open emrys90 opened 1 month ago
Here's how I'm loading the NavMesh
private async void LoadNavMesh()
{
try
{
await using var fileStream = new FileStream("Actors/World/World.bytes", FileMode.Open);
using var br = new BinaryReader(fileStream);
var reader = new DtMeshSetReader();
var navMesh = reader.Read(br, 6);
ProcessQueue(navMesh);
}
catch (Exception ex)
{
this.LogException(ex);
}
}
And here's how I'm generating the NavMesh, by converting Unity's NavMesh to Recast.
private async UniTask PerformBake()
{
this.Log("Enabling baked colliders");
foreach (var bakedCollider in _bakedColliders)
{
bakedCollider.enabled = true;
}
this.Log("Baking Unity NavMesh");
var targets = new Object[] { _navMesh };
NavMeshAssetManager.instance.StartBakingSurfaces(targets);
await UniTask.WaitUntil(() => !NavMeshAssetManager.instance.IsSurfaceBaking(_navMesh));
this.Log("Disabling baked colliders");
foreach (var bakedCollider in _bakedColliders)
{
bakedCollider.enabled = false;
}
NavMeshTriangulation triangles = NavMesh.CalculateTriangulation();
Mesh mesh = new Mesh();
mesh.vertices = triangles.vertices;
mesh.triangles = triangles.indices;
var rc = new UniRcNavMeshSurfaceTarget("World", mesh, Matrix4x4.identity);
var rcMesh = rc.ToMesh();
rcMesh.SaveFile();
var settings = new RcNavMeshBuildSettings()
{
//cellSize = 0.3f,
//cellHeight = 0.2f,
agentHeight = 2.0f,
agentRadius = 0f,
agentMaxClimb = 0.9f,
agentMaxSlope = 45f,
agentMaxAcceleration = 8.0f,
agentMaxSpeed = 3.5f,
minRegionSize = 0,
mergedRegionSize = 20,
//partitioning = RcPartitionType.WATERSHED.Value,
filterLowHangingObstacles = true,
filterLedgeSpans = true,
filterWalkableLowHeightSpans = true,
edgeMaxLen = 12f,
edgeMaxError = 1.3f,
vertsPerPoly = 6,
detailSampleDist = 6f,
detailSampleMaxError = 1f,
tiled = false,
tileSize = _navMesh.tileSize,
keepInterResults = true, // full memory
buildAll = true,
};
var navMesh = rcMesh.Build(settings);
navMesh.SaveNavMeshFile(rc.GetName());
this.Log("Clearing Unity NavMesh data");
NavMeshAssetManager.instance.ClearSurfaces(targets);
}
Hello. Nice to meet you! If it's okay, could I please get the navmesh file?
Oh, and if you have a screenshot of the reproduction steps for the issue, that would be really helpful. I can't quite figure out what the problem is from the screenshots you provided.
Sure, thanks for helping with this! World.zip
I'm trying to prevent the AI from walking into the water when following the player.
The pathfinding will even follow the player into the air. The path returned is just two waypoints, the first being the AI's current location and the end result being the target location. So its as if its not even trying to find the path and just going directly to the result.
When I checked what you provided, I'm not sure what the problem is.
Based on the code you provided:
@ikpil Thanks for the suggestions!
Both are above 0, the values are 281475431792640 for the start, and 281475431792640 for the end. This is for a navigation path when the player is standing in the water area.
I can't find any differences between RctestNavMeshTool::FindFollowPath and my code, it appears to be similar in how the path is called. I thought maybe it was a coordinate system issue with Recast being different from Unity, but when I converted the coordinates, that caused the FindNearestPoly calls to fail.
Progress! I found out its a coordinate conversion issue. What's weird is to fix it I had to do a negative X value for converting from Unity to Recast, but what I found online is its supposed to be a negative Z, so that's a bit odd and no idea why its different.
I've got 2 remaining issues I haven't been able to figure out yet though.
The bridge here, the pathfinding isn't raising up in the air. It instead stays at the same height of the terrain the bridge connects to. This happens if the target position is below the navmesh, so its like its taking the height from the target position instead of the navmesh height.
The pathfinding doesn't find the closest path if the target is off the navmesh, its like it gives up. I tried calling DtNavMeshQuery.ClosestPointOnPoly, but it didn't seem to make a difference.
I have a navmesh that looks like this
My pathfinding is causing the agent to walk through the water, which is the empty area in the center of the screenshot.
Any ideas what I am doing wrong? Here's my code for finding the path. I probably screwed something up, it wasn't easy trying to figure out how to actually find a path using DotRecast. Had to use OpenAI and a lot of trial and error to try and figure it out lol.