use obstacle-in-path pathfinding
This commit is contained in:
+7
-12
@@ -33,11 +33,12 @@ export default class Template {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: fix disabled incremental pathing causes lag spikes
|
||||
// TODO: minion aggro
|
||||
// TODO: incremental pathfinding stuck in thicker than recalculateDestRadius walls
|
||||
static #minionLogic(route = []) {
|
||||
const checkpointSize = 300
|
||||
const incrementalPathing = 100
|
||||
const maxDestDistance = 100
|
||||
const recalculateDestRadius = 50
|
||||
|
||||
return function builtMinionLogic() {
|
||||
const entity = this
|
||||
@@ -46,7 +47,6 @@ export default class Template {
|
||||
if (route.length > 0) {
|
||||
const routeIndex = entity.memory.routeCheckpoint ?? 0
|
||||
const goal = route[routeIndex].clone()
|
||||
const currentTick = entity.game?.currentTick ?? 0
|
||||
if (goal instanceof Vector2) {
|
||||
if (entity.distanceTo(goal) < checkpointSize) {
|
||||
if (routeIndex + 1 < route.length) {
|
||||
@@ -54,20 +54,15 @@ export default class Template {
|
||||
}
|
||||
}
|
||||
|
||||
if ((entity.memory.incrementalPathingTimeout ?? -Infinity) < currentTick) {
|
||||
if ((entity.destination?.distanceTo(entity.position) ?? 0) < recalculateDestRadius) {
|
||||
const distanceToGoal = entity.distanceTo(goal)
|
||||
if (distanceToGoal > entity.memory.distanceToGoal ?? -Infinity) {
|
||||
entity.memory.incrementalPathingTimeout = currentTick + (1 * (entity.game.tickRate ?? 1))
|
||||
}
|
||||
else if (distanceToGoal > incrementalPathing) {
|
||||
const direction = goal.clone().sub(entity.position).normalize().multiplyScalar(incrementalPathing)
|
||||
if (distanceToGoal > maxDestDistance) {
|
||||
const direction = goal.clone().sub(entity.position).normalize().multiplyScalar(maxDestDistance)
|
||||
goal.copy(entity.position.clone().add(direction))
|
||||
}
|
||||
|
||||
entity.memory.distanceToGoal = distanceToGoal
|
||||
entity.attackAction(goal)
|
||||
}
|
||||
|
||||
entity.attackAction(goal)
|
||||
}
|
||||
|
||||
if (entity.position.equals(route.at(-1))) {
|
||||
|
||||
Reference in New Issue
Block a user