disable collision to fix pathfinding phasing through walls

This commit is contained in:
2024-12-25 03:55:32 +09:00
parent 3bb34ed012
commit f48a6bf9aa
4 changed files with 71 additions and 28 deletions
+16 -1
View File
@@ -1,4 +1,5 @@
import { EventEmitter } from 'node:events'
import Pathfind from './pathfind.js'
export default class Game {
tickRate = 30
@@ -10,14 +11,23 @@ export default class Game {
#eventEmitter = new EventEmitter()
#terrains = []
#tickBudget = Math.floor(1000 / this.tickRate)
#waypointGraph = []
get entities() { return this.#entities }
get eventEmitter() { return this.#eventEmitter }
get terrains() { return this.#terrains }
get tickBudget() { return this.#tickBudget }
get waypointGraph() { return this.#waypointGraph }
get unadjustedWaypoints() {
return this.terrains.map((t) => t.unadjustedWaypoints).concat(this.entities.map((e) => e.unadjustedWaypoints)).flat()
// const terrainAndEntities = this.entities.concat(this.terrains)
const terrainAndEntities = this.terrains
return terrainAndEntities.map((e) => e.unadjustedWaypoints).flat()
}
colliders() {
const terrainAndEntities = this.entities.concat(this.terrains)
return terrainAndEntities.map((e) => e.colliders).flat()
}
spawn_entity(entity) {
@@ -32,6 +42,7 @@ export default class Game {
add_terrain(terrain) {
this.#terrains.push(terrain)
this.#calculateWaypointGraph()
}
state() {
@@ -53,4 +64,8 @@ export default class Game {
this.currentTick++
this.eventEmitter.emit('tick')
}
#calculateWaypointGraph() {
this.#waypointGraph = Pathfind.buildGraph(this.unadjustedWaypoints, this.colliders())
}
}