|
|
@@ -467,55 +467,10 @@ export class EnemyInstance extends Component {
|
|
|
|
|
|
// 更新移动逻辑
|
|
|
private updateMovement(deltaTime: number) {
|
|
|
- // 检查是否接近游戏区域边界
|
|
|
- if (this.checkNearGameArea()) {
|
|
|
- this.state = EnemyState.ATTACKING;
|
|
|
- this.attackTimer = 0;
|
|
|
- this.playAttackAnimation();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 继续移动
|
|
|
+ // 继续移动到目标墙体
|
|
|
this.moveTowardsTarget(deltaTime);
|
|
|
}
|
|
|
|
|
|
- // 检查是否接近游戏区域
|
|
|
- private checkNearGameArea(): boolean {
|
|
|
- const currentPos = this.node.worldPosition;
|
|
|
-
|
|
|
- // 获取游戏区域边界
|
|
|
- const gameArea = find('Canvas/GameLevelUI/GameArea');
|
|
|
- if (!gameArea) return false;
|
|
|
-
|
|
|
- const uiTransform = gameArea.getComponent(UITransform);
|
|
|
- if (!uiTransform) return false;
|
|
|
-
|
|
|
- const gameAreaPos = gameArea.worldPosition;
|
|
|
- const halfWidth = uiTransform.width / 2;
|
|
|
- const halfHeight = uiTransform.height / 2;
|
|
|
-
|
|
|
- const bounds = {
|
|
|
- left: gameAreaPos.x - halfWidth,
|
|
|
- right: gameAreaPos.x + halfWidth,
|
|
|
- top: gameAreaPos.y + halfHeight,
|
|
|
- bottom: gameAreaPos.y - halfHeight
|
|
|
- };
|
|
|
-
|
|
|
- // 检查是否在游戏区域内或非常接近
|
|
|
- const safeDistance = 50; // 安全距离
|
|
|
-
|
|
|
- const isInside = currentPos.x >= bounds.left - safeDistance &&
|
|
|
- currentPos.x <= bounds.right + safeDistance &&
|
|
|
- currentPos.y >= bounds.bottom - safeDistance &&
|
|
|
- currentPos.y <= bounds.top + safeDistance;
|
|
|
-
|
|
|
- if (isInside) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
// 移动到目标位置
|
|
|
private moveTowardsTarget(deltaTime: number) {
|
|
|
// 使用世界坐标进行移动计算,确保不受父节点坐标系影响
|