兄弟游戏对象在Unity2D中不发生碰撞。

huangapple go评论76阅读模式
英文:

Sibling game objects not colliding in Unity2D

问题

以下是翻译好的内容:

我有一个游戏,在这个游戏中,敌人的波浪是通过将敌人的排列作为一个空的游戏对象的子级来生成的,然后我可以将其保存为预制件,并使用敌人生成器脚本进行实例化,但是敌人之间没有碰撞,我能想到的唯一原因是由于它们是兄弟节点而导致的一些物理优化。这是我的敌人的碰撞体和刚体设置:兄弟游戏对象在Unity2D中不发生碰撞。 有任何想法为什么会发生这种情况吗?谢谢!

英文:

I have a game in which waves of enemies are spawned by storing an arrangement of enemies as children of an empty game object, which I can then save as a prefab and instantiate with an enemy spawner script, but there is no collision between the enemies, and the only reason I can think of is because of some physics optimization due to them being siblings.<br> These are my collider and rigidbody settings for the enemies: <br> 兄弟游戏对象在Unity2D中不发生碰撞。<br> Any idea why this happens? Thanks!

答案1

得分: 1

这可能是因为你的刚体约束设置为在X和Y轴上冻结移动:

兄弟游戏对象在Unity2D中不发生碰撞。

这意味着通常来自模拟物理交互的运动(例如,与其他敌人碰撞后改变速度)将被忽略。有关详细信息,请参阅Unity文档

在这里的简单修复方法是取消选中这些复选框,以便依赖物理系统处理这些交互。如果你想通过代码完全控制它们,你理论上可以在OnCollisionEnter()中编写代码来处理两个敌人之间的碰撞,但这将是一个更复杂的解决方案。

英文:

This is likely because your Rigidbody constraints are set to freeze movement on both the X and Y axes:

兄弟游戏对象在Unity2D中不发生碰撞。

This means that any movement you would normally expect from simulated physical interactions (for example, changing velocity from colliding with another enemy) will be ignored for this Rigidbody. See the Unity docs for more details on what they do.

The simple fix here would be to uncheck those checkboxes, so that you rely on the physics system to handle these interactions. If you want to fully control them through code though, you could technically write code in OnCollisionEnter() to handle the collision between two enemies - but that would be a much more involved solution.

huangapple
  • 本文由 发表于 2023年2月6日 02:48:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定