obsidian/笔记文件/2.笔记/unity让特定层之间设定碰撞关系.md
2025-03-26 00:02:56 +08:00

15 lines
1010 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#unity/日常积累
unity中我们普遍使用的是碰撞器来实现各个物体的碰撞体积例如Box collider, Sphere Collider。
在实现游戏的过程中如果不想要物体与特定物体产生碰撞或反之只想让碰撞发生在特定物体之间时我们就需要配置layer collision matrix。
首先我们给予需要特殊照顾的物体一个自己的layer这里我想要这个layer里的物体不与玩家碰撞。
当然我们也要为我们的玩家设置自己的层 layer。
之后在 Edit -> Project Settings -> Physics 中我们就需要配置各个层之间的碰撞关系了想要他们之间碰撞的打上勾不想的就取消勾就行以下图为例我取消了player层和NotColliderWithPlayer层之间的碰撞。
![[Pasted image 20230710192911.png]]
如果是在2D场景中我们使用的是2D collider因此我们进行配置的时候也将配置Physics2D而不是Physics。其余的与上述3D场景中的配置是一样的。