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

[FEATURE] auto-nav-bake #43

Closed
EntranceJew opened this issue Feb 25, 2024 · 6 comments · Fixed by #56
Closed

[FEATURE] auto-nav-bake #43

EntranceJew opened this issue Feb 25, 2024 · 6 comments · Fixed by #56
Assignees
Labels
approved Approved feature request completed Issue is resolved but awaiting merge feature New feature or request medium-priority A medium priority issue/PR

Comments

@EntranceJew
Copy link
Contributor

What is the new feature? (required)

when bots should spawn, attempt to run nav_generate_cheap_expanded from Navmesh Optimizer, because it's cheap and inoffensive enough that it's accurate like 99% of the time

if you do include any logic for that then you will get slightly better navmeshes if you provide player spawn positions as seeds as I have done in my side addon:

local bigNegativeZ = Vector( 0, 0, -3000 )
local function snappedToFloor( pos )
	local traceDat = {
		mask = MASK_SOLID,
		start = pos,
		endpos = pos + bigNegativeZ
	}

	local trace = util.TraceLine( traceDat )
	if not trace.Hit then return nil, nil end

	local snapped = trace.HitPos
	if not util.IsInWorld( snapped ) then return nil, nil end

	return true, snapped, trace
end

hook.Add("navoptimizer_comprehensiveseedpositions_postbuilt", "NavMeshGen_postbuilt", function(donePositions)
	local spawnPoints = plyspawn.GetPlayerSpawnPoints()
	for _, spawn in ipairs(spawnPoints) do
		local didSnap, pos = snappedToFloor(spawn.pos)
		if didSnap then
			donePositions[#donePositions + 1] = pos
		end
	end
end)

Purpose/motivation (required)

my server is a testing server largely, so not having any players on at all breaks things, including the ability to conduct a mapvote since a round never starts. this isn't the most intelligent way to handle things but even so, if a map doesn't have a nav it is still a better experience to try and make one for a player when one joins

How would you add this feature? (optional)

wherever that print about navmeshes happens, make it do this instead if navmesh optimizer exists

Context

navvmesh optimizer's incremental one might not be the perfect navmesh but it is surprisingly competent for someone like me who would never bother to go in and even begin authoring one for all the maps we have in rotation if it didn't cover 99% of the problem areas for me

and more importantly it doesn't require a map reload and a bunch of extra shit that could potentially disable a whole server as it generates

@EntranceJew EntranceJew added medium-priority A medium priority issue/PR feature New feature or request labels Feb 25, 2024
@thebigsleepjoe
Copy link
Owner

Will be tackled around the same time as #18 -- actually sounds pretty easy to run an incremental generation if the optimizer addon is installed. Thank you for providing a snippet and some extra background, very helpful.

@thebigsleepjoe
Copy link
Owner

I'm thinking of having a feature like this be a cvar that is automatically enabled (e.g., "ttt_bot_nav_auto 1") and it will generate a navmesh for the map on the first load. Thoughts?

@EntranceJew
Copy link
Contributor Author

EntranceJew commented Mar 25, 2024 via email

@thebigsleepjoe thebigsleepjoe added the approved Approved feature request label Apr 21, 2024
@thebigsleepjoe
Copy link
Owner

Since navmesh optimizer requires sv_cheats to be 1, which is a protected cvar. This is not possible to perform automatically.

Tried:

  • function game.ConsoleCommand
  • Player:ConCommand
  • RunConsoleCommand

The worst part is that I only discovered this fact after writing 98% of the code.... haha....

@thebigsleepjoe thebigsleepjoe closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2024
@thebigsleepjoe thebigsleepjoe reopened this Jun 1, 2024
@thebigsleepjoe
Copy link
Owner

thebigsleepjoe commented Jun 1, 2024

In-progress, working on similar command which can be placed between sv_cheats, as such:

sv_cheats 1; ttt_bot_nav_gen; sv_cheats 0;

@thebigsleepjoe
Copy link
Owner

Unfortunately, I've discovered that even this ^ is impossible. Below is the only working method with the new concommand I'll be adding in v1.3:

  1. Enter sv_cheats 1 in the console
  2. Type ttt_bot_nav_gen
  3. Wait for a bit
  4. Enter sv_cheats 0

We cannot run it synchronously, as N.O. (and nav_generate_incremental, which it relies on) is asynchronous by design. Namely, N.O. uses timers and concommands heavily to generate its navmeshes. Running the above commands is an acceptable solution for small servers or servers of trusted friends, so I'm leaving it in.

If you wish to avoid the prep work, the only solution is to use find navmeshes on the workshop and limit your map pool to maps with navmeshes. I wish more mappers included navmeshes in them.

@thebigsleepjoe thebigsleepjoe added the completed Issue is resolved but awaiting merge label Jun 6, 2024
@thebigsleepjoe thebigsleepjoe linked a pull request Jun 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved feature request completed Issue is resolved but awaiting merge feature New feature or request medium-priority A medium priority issue/PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants