add 'core:pathfinding' component

This commit is contained in:
MihailRis 2025-08-03 19:06:22 +03:00
parent e2d0fa830d
commit a110022ec2
3 changed files with 45 additions and 3 deletions

View File

@ -0,0 +1,39 @@
local target
local route
local started
local tsf = entity.transform
agent = pathfinding.create_agent()
pathfinding.set_max_visited(agent, 100000)
function set_target(new_target)
target = new_target
end
function get_target()
return target
end
function get_route()
return route
end
function on_update()
if not started then
if target then
pathfinding.make_route_async(agent, tsf:get_pos(), target)
started = true
end
else
local new_route = pathfinding.pull_route(agent)
if new_route then
route = new_route
started = false
end
end
end
function on_despawn()
pathfinding.remove_agent(agent)
end

View File

@ -380,9 +380,11 @@ void WorldRenderer::renderFrame(
auto& linesShader = assets.require<Shader>("lines");
linesShader.use();
debugLines->render(
ctx, camera, *lines, *lineBatch, linesShader, showChunkBorders
);
if (debug && hudVisible) {
debugLines->render(
ctx, camera, *lines, *lineBatch, linesShader, showChunkBorders
);
}
linesShader.uniformMatrix("u_projview", projView);
lines->draw(*lineBatch);
lineBatch->flush();

View File

@ -181,6 +181,7 @@ Route Pathfinding::perform(Agent& agent, int maxVisited) {
}
}
}
state.finished = true;
agent.state = std::move(state);
return {};
}