当前位置:   article > 正文

unity3D 射线球体投射碰撞检测_physics.spherecastall

physics.spherecastall

在Unity中,可以从一个点向一个方向发射虚拟球体,指定球体半径、投射长度。

在发射轨迹中与其他物体发生碰撞时,它将终止,并返回碰撞信息。

接口

Physics.SphereCastAll

  1. var screenPos = Input.mousePosition;
  2. // 触碰点的世界坐标,距离摄像机5米的距离
  3. var worldPos = Camera.main.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 5));
  4. // 摄像机的世界坐标
  5. var camPos = Camera.main.transform.position;
  6. // 球体半径
  7. var radius = 0.25f;
  8. // 投射长度
  9. var lineLen = 100;
  10. RaycastHit[] hits = Physics.SphereCastAll(camPos, radius, worldPos - camPos, lineLen);
  11. if(hits.Length > 0)
  12. {
  13. if(hits[0].collider.gameObject.tag == "dddd") //用layer也可以//
  14. {
  15. }
  16. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/1011593
推荐阅读
相关标签
  

闽ICP备14008679号