Walk improvements
This commit is contained in:
@ -8,6 +8,7 @@ export type Node = Position & { parent?: Node; g: number; h: number; f: number }
|
||||
|
||||
class CharacterMoveService extends BaseService {
|
||||
private readonly MOVEMENT_DELAY_MS = 260
|
||||
private readonly MAX_PATH_LENGTH = 20 // Limit maximum path length
|
||||
|
||||
private readonly DIRECTIONS = [
|
||||
{ x: 0, y: -1 }, // Up
|
||||
@ -45,7 +46,21 @@ class CharacterMoveService extends BaseService {
|
||||
return null
|
||||
}
|
||||
|
||||
return this.findPath(start, end, grid)
|
||||
// Add maximum distance check
|
||||
const directDistance = Math.sqrt(Math.pow(targetX - character.positionX, 2) + Math.pow(targetY - character.positionY, 2))
|
||||
|
||||
if (directDistance > this.MAX_PATH_LENGTH) {
|
||||
return null
|
||||
}
|
||||
|
||||
const path = this.findPath(start, end, grid)
|
||||
|
||||
// Validate path length
|
||||
if (path.length > this.MAX_PATH_LENGTH) {
|
||||
return path.slice(0, this.MAX_PATH_LENGTH)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
public calculateRotation(X1: number, Y1: number, X2: number, Y2: number): number {
|
||||
|
Reference in New Issue
Block a user