fix pathfinding for real

This commit is contained in:
2024-12-25 18:12:53 +09:00
parent 8fe48fb679
commit fe4dc8b8bc
3 changed files with 71 additions and 73 deletions
+3 -1
View File
@@ -87,6 +87,8 @@ export default class Entity {
this.position.set(x, y)
}
// TODO: waypoints go out of bounds
// TODO: pathfinding stops if wall is clicked (did you forget to fix the destination?)
async takeStep(distanceTraveled = 0) {
const speed = (this.speed / (this.game?.tickBudget ?? 1000)) - distanceTraveled
const collidables = this.collidables()
@@ -100,11 +102,11 @@ export default class Entity {
const goal = SATX.vectorToFloat32Array(fixedDest)
const nonUniqueWaypoints = this.waypoints().map((w) => SATX.vectorToFloat32Array(w)).concat([start, goal])
const waypoints = Pathfind.uniqueWaypoints(nonUniqueWaypoints)
console.timeEnd('waypoints')
console.time('graph')
const graph = Pathfind.buildGraph(waypoints, collidables, this.radius)
// console.log(Pathfind.formatFloat32Array(graph, 5, true))
// const tunnels = []
// for (let i = 0; i < graph.length; i += 5) {
// tunnels.push(SATX.entityTunnel(graph[i], graph[i + 1], graph[i + 2], graph[i + 3], 1))