Unity射线检测不到MeshCollider的原因

当我们构建的模型是单面模型时,就会出现射线检测不到MeshCollider的问题,对于渲染,我们可以Cull Off来实现双面渲染,而在射线检测时,Unity提供了一个API来控制是否检测背面:Physics.queriesHitBackfaces

案例代码:

csharp 复制代码
public bool Raycast(out RaycastHit hitOnGround, out RaycastHit hitOnStructure) 
{
    Physics.queriesHitBackfaces = true;
    
    Ray ray = m_Camera.ScreenPointToRay(Input.mousePosition);
    Physics.Raycast(ray, out hitOnGround, m_Camera.farClipPlane * 2, m_GroundLayer);
    bool onStructure = Physics.Raycast(ray, out hitOnStructure, m_Camera.farClipPlane * 2, m_StructureLayer);
    
    Physics.queriesHitBackfaces = false;

    return onStructure;
}
相关推荐
XR-AI-JK2 小时前
Unity VR/MR开发-VR/开发SDK选型对比分析
unity·vr·mr
心之所向,自强不息9 小时前
【Unity Shader编程】之让画面动起来
unity·游戏引擎
不伤欣1 天前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
Magnum Lehar1 天前
vulkan游戏引擎test文件memory实现
游戏引擎
Magnum Lehar1 天前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
快乐觉主吖1 天前
Unity的日志管理类
android·unity·游戏引擎
WarPigs2 天前
Unity性能优化笔记
笔记·unity·游戏引擎
T.D.C2 天前
【业务框架】3C-相机-Cinemachine
unity
一线灵2 天前
跨平台游戏引擎 Axmol-2.6.1 发布
游戏引擎
Clank的游戏栈3 天前
Unity基于GraphView的可视化关卡编辑器开发指南
unity·编辑器·游戏引擎