|
|
@@ -44,6 +44,13 @@ export class BallController extends Component {
|
|
|
start() {
|
|
|
// 计算游戏边界
|
|
|
this.calculateGameBounds();
|
|
|
+
|
|
|
+ // 检查子弹预制体是否已设置
|
|
|
+ if (this.bulletPrefab) {
|
|
|
+ console.log('子弹预制体已设置:', this.bulletPrefab.name);
|
|
|
+ } else {
|
|
|
+ console.error('子弹预制体未设置!请在编辑器中设置bulletPrefab属性');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 计算游戏边界(使用GameArea节点)
|
|
|
@@ -76,32 +83,6 @@ export class BallController extends Component {
|
|
|
|
|
|
console.log('GameArea Bounds:', this.gameBounds);
|
|
|
|
|
|
- // 查找并输出墙体节点信息
|
|
|
- this.logWallInfo();
|
|
|
- }
|
|
|
-
|
|
|
- // 输出墙体节点信息
|
|
|
- logWallInfo() {
|
|
|
- const gameArea = find('Canvas/GameLevelUI/GameArea');
|
|
|
- if (!gameArea) return;
|
|
|
-
|
|
|
- // 查找墙体节点
|
|
|
- const walls = ['TopFence', 'BottomFence', 'JiguangL', 'JiguangR'];
|
|
|
- walls.forEach(wallName => {
|
|
|
- const wall = gameArea.getChildByName(wallName);
|
|
|
- if (wall) {
|
|
|
- const transform = wall.getComponent(UITransform);
|
|
|
- const collider = wall.getComponent(Collider2D);
|
|
|
- console.log(`墙体节点 ${wallName} 信息:`, {
|
|
|
- position: wall.worldPosition,
|
|
|
- size: transform ? { width: transform.width, height: transform.height } : 'unknown',
|
|
|
- hasCollider: !!collider,
|
|
|
- colliderType: collider ? collider.constructor.name : 'none'
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.warn(`找不到墙体节点 ${wallName}`);
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
// 创建小球
|
|
|
@@ -255,6 +236,9 @@ export class BallController extends Component {
|
|
|
otherPath: this.getNodePath(otherCollider.node)
|
|
|
});
|
|
|
|
|
|
+ // Debug: 检查节点名称是否包含Block
|
|
|
+ console.log(`检查节点名称: "${otherCollider.node.name}",是否包含'Block': ${otherCollider.node.name.includes('Block')}`);
|
|
|
+
|
|
|
// 获取碰撞点的世界坐标
|
|
|
const worldManifold = contact.getWorldManifold();
|
|
|
if (!worldManifold) {
|
|
|
@@ -346,7 +330,14 @@ export class BallController extends Component {
|
|
|
}
|
|
|
|
|
|
// 如果碰撞的是方块,发射子弹
|
|
|
- if (otherCollider.node.name.includes('Block')) {
|
|
|
+ // 修改检测逻辑,使用更宽松的条件
|
|
|
+ const isBlock =
|
|
|
+ nodeName.includes('Block') ||
|
|
|
+ nodePath.includes('Block') ||
|
|
|
+ (otherCollider.node.getChildByName('Weapon') !== null);
|
|
|
+
|
|
|
+ if (isBlock) {
|
|
|
+ console.log(`检测到方块碰撞: ${nodeName}, 路径: ${nodePath}`);
|
|
|
this.fireBullet(otherCollider.node);
|
|
|
}
|
|
|
}
|
|
|
@@ -436,6 +427,8 @@ export class BallController extends Component {
|
|
|
if (!this.bulletPrefab) {
|
|
|
console.error('未设置子弹预制体');
|
|
|
return;
|
|
|
+ } else {
|
|
|
+ console.log('子弹预制体已设置:', this.bulletPrefab.name);
|
|
|
}
|
|
|
|
|
|
// 查找Weapon节点
|
|
|
@@ -443,6 +436,8 @@ export class BallController extends Component {
|
|
|
if (!weaponNode) {
|
|
|
console.warn(`方块 ${blockNode.name} 没有Weapon子节点`);
|
|
|
return;
|
|
|
+ } else {
|
|
|
+ console.log(`找到方块 ${blockNode.name} 的Weapon子节点:`, weaponNode.name);
|
|
|
}
|
|
|
|
|
|
// 实例化子弹
|
|
|
@@ -518,16 +513,10 @@ export class BallController extends Component {
|
|
|
// 手动检测墙体碰撞
|
|
|
this.checkWallCollisions();
|
|
|
|
|
|
- // 每隔一段时间输出小球状态信息
|
|
|
- if (Math.random() < 0.01) { // 约每100帧输出一次
|
|
|
- console.log('小球状态:', {
|
|
|
- position: this.activeBall.worldPosition,
|
|
|
- velocity: rigidBody.linearVelocity,
|
|
|
- speed: speed,
|
|
|
- direction: this.direction
|
|
|
- });
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+ // 手动检测方块碰撞
|
|
|
+ this.checkBlockCollisions();
|
|
|
}
|
|
|
|
|
|
// 手动检测墙体碰撞
|
|
|
@@ -615,6 +604,35 @@ export class BallController extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 手动检测方块碰撞
|
|
|
+ checkBlockCollisions() {
|
|
|
+ if (!this.activeBall) return;
|
|
|
+
|
|
|
+ // 获取场景中所有方块
|
|
|
+ const placedBlocks = find('Canvas/PlacedBlocks');
|
|
|
+ if (!placedBlocks) return;
|
|
|
+
|
|
|
+ const ballPos = this.activeBall.worldPosition;
|
|
|
+ const ballRadius = this.radius;
|
|
|
+
|
|
|
+ // 检查与每个方块的碰撞
|
|
|
+ for (let i = 0; i < placedBlocks.children.length; i++) {
|
|
|
+ const block = placedBlocks.children[i];
|
|
|
+ if (!block.name.includes('Block')) continue;
|
|
|
+
|
|
|
+ // 简单距离检测(可以根据实际情况优化)
|
|
|
+ const blockPos = block.worldPosition;
|
|
|
+ const distance = Vec3.distance(ballPos, blockPos);
|
|
|
+
|
|
|
+ // 如果距离小于某个阈值,认为发生碰撞
|
|
|
+ if (distance < ballRadius + 50) { // 50是一个估计值,根据方块大小调整
|
|
|
+ console.log('手动检测到与方块碰撞:', block.name);
|
|
|
+ this.fireBullet(block);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 初始化方向
|
|
|
initializeDirection() {
|
|
|
// 随机初始方向
|