c# - 当第二层在第一层和第三层之间时,如何避免它们之间的碰撞?Unity 2D C#
问题描述
我有 3 层:car、track和outOfTrack层。在car和track下是outOfTrack层。当汽车在轨道上时,会检测到汽车和outOfTrack之间的碰撞,所以我想以某种方式避免它。
如何避免在汽车在轨道上时检测汽车与outOfTrack之间的碰撞,并且仅在汽车接触outOfTrack时才检测它?
解决方案
Go to Edit->ProjectSettings->Physics. There you have the collision matrix. With the checkboxes you define which layer collides with which.
Edit: The collision matrix isn't supposed to change all existing contacts in realtime. If we were to do this, we'd have to re-evaluate every single contact in the world which could be very expensive and is easily abused. Check this. So you can try to change the collision matrix with code, you can probably do so, however I would suggest to handle the collisions thinking of them in terms of space, not time.
By this I mean that you try to detect the collision not at the time when your car is out of track, but, with the corresponding layers and colliders, detect the collision where its out of track.
If you are still into changing the collision matrix in runtime you can try check out the docs
推荐阅读
- php - foreach、if、else php 的问题
- redux - 如何在 Saga 中重新调度动作,如 redux 工具包自动重新获取
- python - Graphviz - pango.dll 的依赖项丢失
- opencv - 如何拼接两个具有不同绝对坐标的图像?
- python - 如何在 tkinter 键绑定输入上设置冷却时间
- python - 为什么选择“加载文件”时,它不能显示XLSX数据,出现消息框“您选择的文件无效”
- sink - 将数据从单个源发送到多个目标/接收器
- java - 改造 JSON 数组和对象现在工作类
- python - 使用条件在另一个 numpy 数组中组织数组
- javascript - 如何解决 MongoDB 中的最大大小问题?