revert "disable collision to fix pathfinding phasing through walls"

This reverts commit f48a6bf9aa.
This commit is contained in:
2024-12-25 09:36:34 +09:00
parent 2570f32592
commit 5acc827f7b
4 changed files with 28 additions and 71 deletions
+9 -18
View File
@@ -2,7 +2,6 @@ import { Vector2 } from 'three'
import SAT from 'sat'
import SATX from './satx.js'
import Pathfind from './pathfind.js'
import Terrain from './terrain.js'
export default class Entity {
id = crypto.randomUUID()
@@ -95,18 +94,13 @@ export default class Entity {
if (this.#path.length < 1 || !this.#path.at(-1).equals(this.#dest)) {
console.time('pathfinding')
console.time('waypoints')
const extraWaypoints = [[this.position, new Vector2()], [fixedDest, new Vector2()]]
const waypoints = (this.game?.unadjustedWaypoints ?? []).concat(extraWaypoints)
const waypoints = (this.game?.unadjustedWaypoints.map(([unadjusted, direction]) => unadjusted.clone().add(direction.clone().multiplyScalar(this.radius))) ?? []).concat([this.position, fixedDest])
console.timeEnd('waypoints')
console.time('extraEntries')
const extraGraphEntries = Pathfind.buildGraph(waypoints, this.collidables(), extraWaypoints)
console.timeEnd('extraEntries')
console.time('unadjustedGraph')
const unadjustedGraph = (this.game?.waypointGraph ?? []).concat(extraGraphEntries)
console.timeEnd('unadjustedGraph')
console.time('graph')
const graph = Pathfind.buildGraph(waypoints, this.collidables(), this.radius)
console.timeEnd('graph')
console.time('path')
this.#path = Pathfind.shortestPath(unadjustedGraph, this.position, fixedDest).map(([unadjusted, direction]) => unadjusted.clone().add(direction.clone().multiplyScalar(this.radius)))
console.log(this.#path)
this.#path = Pathfind.shortestPath(graph, this.position, fixedDest)
console.timeEnd('path')
console.timeEnd('pathfinding')
}
@@ -119,15 +113,12 @@ export default class Entity {
const position = distance <= speed ? destination : stepTaken
const collider = Entity.collider(position.x, position.y, this.radius)
// TODO: fix collisions while pathfinding
// const isColliding = SATX.collideObjects(collider, this.collidables())
const isColliding = SATX.collideObjects(collider, this.collidables())
// if (!isColliding) {
// this.position.copy(position)
// }
if (!isColliding) {
this.position.copy(position)
}
this.position.copy(position)
if (this.position.equals(destination)) {
this.#path = this.#path.slice(1)
if (this.#path.length > 0) {