I'm trying to compute the shortest walkable distance from one position to another. All I've been able to find is PathFollower for NextBots, and it's certainly less than ideal to have to spawn a NextBot everytime I want to find a path.
How can I best do this?
[editline]28th January 2015[/editline]
NavSetGoal or NavSetGoalTarget and then GetPathDistanceToGoal returns 0 everytime.
The Nextbot pathing require for the map to have a nav mesh. There's no other way tho. You should be able to do this without spawning a nextbot.
[QUOTE=Robotboy655;47029793]The Nextbot pathing require for the map to have a nav mesh. There's no other way tho. You should be able to do this without spawning a nextbot.[/QUOTE]
So if I use navmesh.BeginGeneration() after map initialization, then standard NPC NavGoal's should work?
It's a bit more than that. You will need to mark walkable positions before you generate a navmesh ( you only need to do this once ) and it is not guaranteed to properly generate ( i.e. It may not cover ALL of walkable places.
[QUOTE=Robotboy655;47029832]It's a bit more than that. You will need to mark walkable positions before you generate a navmesh ( you only need to do this once ) and it is not guaranteed to properly generate ( i.e. It may not cover ALL of walkable places.[/QUOTE]
Roughly how many of these do I need to mark? I'm using rp_evocity_v4b1, and I just need the paths to follow the roads throughout the map. If I mark each corner would that be enough?
You'll need at least one, more for closed spaces, etc.
[QUOTE=Robotboy655;47030057]You'll need at least one, more for closed spaces, etc.[/QUOTE]
I still cant seem to get anything except 0 as a navigation distance.
[LUA]
local walkables = { -- For v4b1
{Pos = Vector(-5981.695801, -5433.765137, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-5107.612793, -5467.514160, 135.938446), Normal = Vector(-0.122126, 0.000000, 0.992515)},
{Pos = Vector(-4291.057129, -5498.983398, 190.031250), Normal = Vector(0.000000, -0.000000, 1.000000)},
{Pos = Vector(-4339.513184, -8261.281250, 190.031250), Normal = Vector(0.000000, -0.000000, 1.000000)},
{Pos = Vector(-5181.629883, -8289.219727, 126.830925), Normal = Vector(-0.122126, 0.000000, 0.992515)},
{Pos = Vector(-5964.846680, -8270.581055, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-9875.673828, -8340.069336, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-9840.316406, -12205.346680, 64.031250), Normal = Vector(0.000000, -0.000000, 1.000000)},
{Pos = Vector(-6015.709961, -12212.805664, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-8165.746582, -5422.216309, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-5789.444824, -810.553772, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-939.861450, -621.934875, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(108.404266, 5034.534668, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(4744.992188, 4989.641602, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(3754.816406, 8668.772461, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-466.986053, -6407.368652, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(7634.926270, -6009.756348, 64.031250), Normal = Vector(-0.000000, 0.000000, 1.000000)},
{Pos = Vector(8829.926758, 1001.635437, 64.031250), Normal = Vector(0.000000, -0.000000, 1.000000)},
{Pos = Vector(8895.788086, 3529.976318, 0.031254), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(12026.563477, 6135.670410, 64.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(7804.645508, 11806.652344, 58.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(3441.934814, 9893.889648, 58.031258), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(3414.085205, 12547.601563, 50.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-1050.318970, 12617.933594, 58.031219), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-3332.344727, 14882.638672, 109.304626), Normal = Vector(0.062379, -0.000000, 0.998052)},
{Pos = Vector(-5455.393555, 12739.565430, 186.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-7861.977539, 10718.952148, 186.031250), Normal = Vector(0.000000, 0.000000, 1.000000)},
{Pos = Vector(-10829.360352, 10773.279297, 185.369659), Normal = Vector(0.000374, 0.003576, 0.999994)},
{Pos = Vector(-13488.463867, 11384.133789, 186.313904), Normal = Vector(0.000601, -0.001504, 0.999999)},
{Pos = Vector(-7663.383789, 9631.949219, 117.741272), Normal = Vector(0.000000, -0.128978, 0.991647)},
{Pos = Vector(-4851.162598, 8173.392090, 63.619957), Normal = Vector(0.000000, 0.001942, 0.999998)},
{Pos = Vector(-5005.120605, 196.842484, 64.031250), Normal = Vector(0.000000, -0.000000, 1.000000)},
}
hook.Add("InitPostEntity, "NavmeshCreationTest", function()
for k,v in pairs(walkables) do
navmesh.AddWalkableSeed(v.Pos, v.Normal)
end
navmesh.BeginGeneration()
end)
function CalculateDistance(begin, destination)
local start = ents.Create("npc_citizen")
start:SetRenderMode(RENDERMODE_TRANSALPHA)
start:SetColor(Color(255,255,255,0))
start:SetPos(begin)
start:Spawn()
start:GetPhysicsObject():EnableCollisions(false)
start:NavSetGoal(destination)
print(tostring(begin))
print(tostring(destination))
print(start:GetPathDistanceToGoal())
start:Remove()
end
[/LUA]
Outputs:
[CODE]
-6013.653320 -8595.858398 88.319733
968.000000 -5983.634766 0.00000
0
[/CODE]
On the note of navmesh generation, does anyone else get a lua panic error regularly while trying to generate?
[QUOTE=Phoenixf129;47035196]On the note of navmesh generation, does anyone else get a lua panic error regularly while trying to generate?[/QUOTE]
Seems to have been generating normally on my localhost. Consistently get:
[CODE]
Generating Navigation Mesh...
[/CODE]
at launch.
[editline]29th January 2015[/editline]
Normally aside from the fact that it doesn't seem to function... lol
Generating rp_evocity_v33x took a few hours of Garry's Mod "Not Responding". Probably 4-6ish hours.
[QUOTE=Acecool;47035428]Generating rp_evocity_v33x took a few hours of Garry's Mod "Not Responding". Probably 4-6ish hours.[/QUOTE]
Oh I didn't realize it was that kind of deal. Where's it saved when it finishes, and how do I know it finished properly?
[QUOTE=RealDope;47035570]Oh I didn't realize it was that kind of deal. Where's it saved when it finishes, and how do I know it finished properly?[/QUOTE]
In your maps folder, and it will tell you when it's finished.
I had it generate automatically after adding a start-point because vector_origin was a little below the map surface.
As Phoenix says, it'll let you know; plus your game will start responding again!
[QUOTE=Acecool;47036731]I had it generate automatically after adding a start-point because vector_origin was a little below the map surface.
As Phoenix says, it'll let you know; plus your game will start responding again![/QUOTE]
My game? This is a serverside thing, no? I'm running navmesh.BeginGeneration() on the server, and it's been responding normally for about 4 hours now without any mention of the nav file except this when it started up:
[CODE]
Generating Navigation Mesh...
Nav File is wrong or something (1)
[/CODE]
Furthermore you are you using non Nextbot NPC ( and non nextbot/navmesh functions ) to get the distance, essentially you are trying to use the old navigation system, which involves manually pressing hundreds of AI nodes on the map.
See these functions:
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/entities/base_nextbot/sv_nextbot.lua#L151-L223[/url]
And the MoveToPos one.
[QUOTE=Robotboy655;47038973]Furthermore you are you using non Nextbot NPC ( and non nextbot/navmesh functions ) to get the distance, essentially you are trying to use the old navigation system, which involves manually pressing hundreds of AI nodes on the map.
See these functions:
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/entities/base_nextbot/sv_nextbot.lua#L151-L223[/url]
And the MoveToPos one.[/QUOTE]
Yeah but as I said in the OP, I don't want to have to create a NextBot just to calculate distance, and Path:Compute() requires one to be passed as the first argument. Can I avoid that somehow?
[QUOTE=RealDope;47049273]Yeah but as I said in the OP, I don't want to have to create a NextBot just to calculate distance, and Path:Compute() requires one to be passed as the first argument. Can I avoid that somehow?[/QUOTE]
Nope, the whole pathing system asks for one for features such as falling damage, step height and all that crap, and it's not even easy to remove that need in the source code.
[QUOTE=Jvs;47052533]Nope, the whole pathing system asks for one for features such as falling damage, step height and all that crap, and it's not even easy to remove that need in the source code.[/QUOTE]
Alright, well I guess I'll just keep an invisible NextBot around to handle my pathing all the time.. Seems pretty silly to me that there's no other way to compute a path..
Anyways, I've generated the nav file and have it on both the server and client. I still see:
[CODE]
Nav File is wrong or something (4)
[/cODE]
at launch, and any PathFollower's I create are never valid (IsValid() is false no matter what).
[editline]1st February 2015[/editline]
navmesh.GetNavAreaCount() returns 19376, so the navmesh appears to be working.
Is this not the proper way to do what I'm attempting?
[LUA]
local begin = Vector(2630, -6520, 128)
local destination = Vector(2800, -6520, 128)
local start = player.CreateNextBot("PATHING BOT")
start:SetRenderMode(RENDERMODE_TRANSALPHA)
start:SetColor(Color(255,255,255,0))
start:Spawn()
start:SetPos(begin)
start:GetPhysicsObject():EnableCollisions(false)
local path = Path("Follow")
path:SetGoalTolerance(20)
path:SetMinLookAheadDistance(300)
path:Compute(start, destination)
print(tostring(path:IsValid())) -- false everytime
start:Remove()
[/LUA]
The path settings etc are straight from ENT:MoveToPos() that Robotboy linked earlier.
[editline]1st February 2015[/editline]
Sorry didn't mean to double post, it didn't auto merge for some reason?
[editline]1st February 2015[/editline]
[lua]
print(tostring(start)) -- Prints [PLAYER]xxx
[/lua]
Perhaps this is why? Do the Path functions actually work? player.CreateNextBot seems to make an entity with Player type, not NextBot.
[QUOTE=RealDope;47056415]
Perhaps this is why? Do the Path functions actually work? player.CreateNextBot seems to make an entity with Player type, not NextBot.[/QUOTE]
Please, read the wiki next time.
[quote]
This bot is also a NextBot internally, [B][U]support for calling NextBot functions ( NextBot ) on it will come at a later date[/U][/B], complete with access to the vision interface and a way to define your own AI.
[/quote]
I literally started following this post from the start, and I want to help but I don't know nothing about pathing. Also at least I'm learning something.
Why do you need this pathing thing, if I can ask you
[QUOTE=Jvs;47059148]Please, read the wiki next time.[/QUOTE]
I actually read that, so no need to be condescending.
I was hoping that it being a "NextBot internally" meant I could still pass it into a function as one.
If that's the case, is there really no way to find the distance of a walkable path between two points?.. I don't even need the path to be accurate enough to actually walk on, just to get a rough "walkable distance" between two points.
Sorry, you need to Log In to post a reply to this thread.