Unity 2D 物理 - 球穿过物体而不是弹回
Unity 2D physics - ball passes through object instead of bouncing back
我关注了这个youtube tutorial to create a Breakout game using Unity. Everything is okay apart from the contact between the ball and blocks. Instead of the ball bouncing back in the opposite direction when it collides with a block, it moves in the same direction. I am not too sure what is causing this issue. I am using version 5.2.3f1 but version 4.6.1f1 was used in the tutorial. I've uploaded my project to this link
- 确保对象具有刚体组件
- 确保物体有碰撞器
- 确保对象位于可以相互碰撞的图层上(参见Edit\Project Settings\Physics 2D:图层碰撞矩阵)
- 确保您使用物理(
obj.GetComponent<Rigidbody>().MovePosition(...);
或应用 forces/impulses)移动对象。如果你只是修改 obj.transform.position
,它 不会 工作
- 假设物体 A 和 B 发生碰撞,请确保不要在它们碰撞的同一帧中销毁它们中的任何一个。如果你在它的 OnCollisionEnter2D 处理程序中销毁 A,B 可能永远不会知道它与 A 发生了碰撞。你可以使用像
Destroy(gameObject, 0.1f);
这样的延迟销毁(将在 .1 秒后销毁 gameObject
)
我关注了这个youtube tutorial to create a Breakout game using Unity. Everything is okay apart from the contact between the ball and blocks. Instead of the ball bouncing back in the opposite direction when it collides with a block, it moves in the same direction. I am not too sure what is causing this issue. I am using version 5.2.3f1 but version 4.6.1f1 was used in the tutorial. I've uploaded my project to this link
- 确保对象具有刚体组件
- 确保物体有碰撞器
- 确保对象位于可以相互碰撞的图层上(参见Edit\Project Settings\Physics 2D:图层碰撞矩阵)
- 确保您使用物理(
obj.GetComponent<Rigidbody>().MovePosition(...);
或应用 forces/impulses)移动对象。如果你只是修改obj.transform.position
,它 不会 工作
- 假设物体 A 和 B 发生碰撞,请确保不要在它们碰撞的同一帧中销毁它们中的任何一个。如果你在它的 OnCollisionEnter2D 处理程序中销毁 A,B 可能永远不会知道它与 A 发生了碰撞。你可以使用像
Destroy(gameObject, 0.1f);
这样的延迟销毁(将在 .1 秒后销毁gameObject
)