TokisanGames / Terrain3D

A high performance, editable terrain system for Godot 4.
MIT License
1.89k stars 106 forks source link

In the CodeGenerated demo, pathfinding is jerky #394

Closed JekSun97 closed 2 weeks ago

JekSun97 commented 1 month ago

Terrain3D version

v0.9.2-dev

System information

Godot v4.2.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 560 Series (Advanced Micro Devices, Inc.; 31.0.14001.45012) - Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz (4 Threads)

Is the issue reproducable in the demo?

Yes

Issue description

When I started the CodeGenerated.tscn demo, the agent’s path search was intermittent with long delays, there were times when the agent stood next to me and for about 6 seconds could not find the path to me

https://github.com/TokisanGames/Terrain3D/assets/130399274/418d7c81-55e4-4728-9baa-b0a35c28b16e

Logs

Empty

tcoxon commented 3 weeks ago

There are a few reasons for this, but it's not a bug. It's a lot clearer why it happens if you make navigation visible:

image

https://github.com/TokisanGames/Terrain3D/assets/165720/d1867aca-105f-45ea-9171-cde7d0e39bb9

The blue mesh that covers the ground is the navigation mesh. The RuntimeNavigationBaker script periodically rebakes this on a thread. You can adjust the "bake cooldown" on the baker to do this more frequently, but you'll still run into the fact that baking navigation is just slow. This is why editor/compile-time baking navigation is usually a better option for games (where that can be done).

However, runtime baking can still be usable. There are a few things you can do to speed it up, or work around the slowness:

A second, smaller delay is due to how frequently the navigation agent updates its path. You can do this more frequently by adjusting the RETARGET_COOLDOWN constant (currently 1.0 seconds), but if you have a lot of agents that's going to come with a performance cost.

JekSun97 commented 3 weeks ago

Thanks, I think this should be mentioned somewhere in the documentation

TokisanGames commented 2 weeks ago

@tcoxon Thanks for looking at it and providing the explanation.

Docs updated in https://github.com/TokisanGames/Terrain3D/commit/15ff7e5b89dfc58fd6d9336924679a6780ef111e