敌人不受子弹的影响
这很愚蠢,但我似乎无法修复它。敌人是场景中的随机实例,因此我将脚本附加到具有此代码的主要敌人场景上:
func _on_Enemy_body_entered(body):
if is_in_group("bullet"):
Player.score += 1
queue_free()
子弹场景,当玩家射击在一个称为“子弹”的小组中时,它也将其本身在主要场景中。
This is very stupid but I can't seem to fix it. The enemy is randomly instance in the scene so I attached a script to the main enemy scene that has this code:
func _on_Enemy_body_entered(body):
if is_in_group("bullet"):
Player.score += 1
queue_free()
The bullet scene which is also instanced to the main scene when the player shoots is in a group called "bullet".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,通常的调试方法适用:
鉴于代码,我希望您发现IF语句中的代码根本根本没有执行。
您说代码在敌人中。敌人是一个叫做“子弹”的群体?我猜不是。因此,
is_in_group(“ Bullet”)
评估false
,因此执行流不输入IF语句。需要清楚,
如果IS_IN_GROUP(“ Bullet”):
与If self.is_in_group(“ Bullet”):
相同。它在附加脚本的对象上调用is_in_group
。由于您提到子弹位于一个名为“子弹”的小组中,因此我还会猜测您想检查敌人相撞的尸体。也就是说:
应该更好。
我看不到您删除子弹,但我无法分辨是否是故意的。
通常考虑检测碰撞。因此,它可能仍然不起作用。您可以看到其他地方以进行完整的说明。对于简短版本:检查是否启用了监视(并且报告的联系人在刚体上足够大),并检查碰撞层和口罩重叠,并且碰撞形状未被禁用,当然,请检查信号是否连接。
First of all, the usual debugging approaches apply:
Given the code, I expect you to find that the code inside the if statement is not executing at all.
You say the code is in the enemy. Is the enemy is a group called "bullet"? I'm going to guess it isn't. So
is_in_group("bullet")
evaluates tofalse
, and thus the execution flow does not enter the if statement.To be clear,
if is_in_group("bullet"):
is the same asif self.is_in_group("bullet"):
. It is callingis_in_group
on the object on which the script is attached.Since you mention the bullet is in a group called "bullet", I'm also going to guess you want to check the body that collided the enemy. That is:
That should be better.
I don't see you delete bullet, but I can't tell if that is intended or not.
There are the usual consideration to detect collisions. So it might still not work. You can see elsewhere for a full explanation. For the short version: check if monitoring is enabled (and contacts reported is large enough on rigid bodies), and check the collision layers and masks overlap, and that the collision shapes are not disabled, and of course check that the signals are connected.