improve position fixing
This commit is contained in:
+11
-15
@@ -64,23 +64,20 @@ export default class Entity {
|
||||
return entityColliders.concat(terrainColliders)
|
||||
}
|
||||
|
||||
// DEPRECATED: hulls were a failed concept for position fixing
|
||||
collidableHulls() {
|
||||
const entityColliders = (this.game?.entities ?? []).filter((e) => e.id != this.id).map((e) => e.collider)
|
||||
const terrainColliders = (this.game?.terrains ?? []).map((t) => t.hull)
|
||||
|
||||
return entityColliders.concat(terrainColliders)
|
||||
}
|
||||
|
||||
isColliding(...colliders) {
|
||||
return SATX.collideObjects(this.collider, colliders)
|
||||
}
|
||||
|
||||
// TODO: calculate convex hulls of collidables because tris handle collisions sequentially
|
||||
moveAction(x, y) {
|
||||
const temp = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius)
|
||||
// const entity = new Entity()
|
||||
// entity.teleport(temp.x, temp.y)
|
||||
// entity.radius = this.radius
|
||||
// this.game.spawn_entity(entity)
|
||||
this.#dest = SATX.clamp(
|
||||
temp,
|
||||
this.game?.width,
|
||||
this.game?.height,
|
||||
this.radius,
|
||||
)
|
||||
this.#dest = SATX.fixCollisions(new Vector2(x, y), this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
}
|
||||
|
||||
state() {
|
||||
@@ -97,7 +94,6 @@ export default class Entity {
|
||||
this.position.set(x, y)
|
||||
}
|
||||
|
||||
// TODO: pathfinding stops if wall is clicked (did you forget to fix the destination?)
|
||||
takeStep(distanceTraveled = 0) {
|
||||
const speed = (this.speed / (this.game?.tickBudget ?? 1000)) - distanceTraveled
|
||||
const collidables = this.collidables()
|
||||
@@ -105,14 +101,14 @@ export default class Entity {
|
||||
const fixedDest = SATX.clamp(SATX.fixCollisions(this.#dest, collidables, this.radius), this.game?.width, this.game?.height, this.radius)
|
||||
|
||||
if (this.#path.length < 1 || !this.#path.at(-1).equals(fixedDest)) {
|
||||
console.time('pathfinding')
|
||||
// console.time('pathfinding')
|
||||
const start = SATX.vectorToFloat32Array(this.position)
|
||||
const goal = SATX.vectorToFloat32Array(fixedDest)
|
||||
const nonUniqueWaypoints = this.waypoints().map((w) => SATX.vectorToFloat32Array(w)).concat([start, goal])
|
||||
const waypoints = Pathfind.uniqueWaypoints(nonUniqueWaypoints)
|
||||
const graph = Pathfind.buildGraph(waypoints, collidables, this.radius)
|
||||
this.#path = Pathfind.shortestPath(graph, start, goal).map((waypoint) => new Vector2(waypoint[0], waypoint[1]))
|
||||
console.timeEnd('pathfinding')
|
||||
// console.timeEnd('pathfinding')
|
||||
}
|
||||
|
||||
if (this.#path.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user