unity3d 怎么把鼠标坐标转成世界坐标
来源:互联网 发布:淘宝售后人员工作流程 编辑:程序博客网 时间:2024/06/06 12:55
第一种:这是一种发射线,获取当前点击的物体(具有碰撞器)的坐标点(也就是碰撞器范围的坐标点)if (Input.GetMouseButtonDown(0)){RaycastHit hitt = new RaycastHit();Ray ray =Camera.main.ScreenPointToRay(Input.mousePosition);Physics.Raycast(ray, out hitt);Debug.Log(hitt.point);//Debug.Log(Camera.main.ScreenToWorldPoint(Input.mousePosition));}第二种:直接获取场景中的坐标点Debug.Log(.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10.0f)));
注意:这里容易出现的问题是,从鼠标坐标点转成世界坐标点的时候,新的三维向量Z轴的赋值必须不能是0.0f,因为,屏幕坐 标点的Z轴,其实是相对于当前摄像机的,如果是0,只能转一次世界坐标系,剩下的不管点哪里都是一个值,所以不能把Z值设为和摄像机的Z坐标重合,我们需要设置一个非0的数字,最后转成世界坐标系后的值是,摄像机的Z轴加上所设置的值。例如当前摄像机Z坐标是10f,我所设置的Z值是10f,最后转成世界坐标系后的Z值就是20;下面是老外的经典回复。
Thereare two problems here. The first one is that you need a 'new' in front of yourVector3() in C#. The second is that the 'z' parameter must be the distance infront of the camera. In perspective mode at least, passing 0 will causeScreenToWorldPoint() to always return the position of the camera. So the callwill look something like:
worldPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, 10.0f));
Notethe measurement for the 'z' parameter is from camera plane to the playingsurface plane. It is not the distance between the camera and the object. If thecamera is aligned with the axes, then the distance is easy to calculate. If thecamera is at an angle (i.e. not axes aligned), then ScreenToWorldPoint() is notthe way to go.原帖:https://zhidao.baidu.com/question/1307485274876283019.html
阅读全文
0 0
- unity3d 怎么把鼠标坐标转成世界坐标
- Unity3D世界坐标转成UI坐标
- 解决Unity鼠标坐标点转成世界坐标系坐标点
- unity3d鼠标点击,获取世界坐标
- unity3d鼠标点击,获取世界坐标
- 将世界坐标转成NGUI坐标
- 将世界坐标转成NGUI坐标
- 鼠标坐标转换成世界坐标
- 【Unity3D】世界坐标与屏幕坐标
- [unity3d]navmesh 自动寻路 鼠标点击的坐标获取 鼠标点击的世界坐标
- Unity3D中世界坐标转换到NGUI世界坐标
- OGRE的2D坐标、CEGUI坐标、鼠标坐标、 世界坐标转屏幕坐标
- OGRE的2D坐标、CEGUI坐标、鼠标坐标、 世界坐标转屏幕坐标
- 把Gps坐标转成百度坐标的java方法
- unity3D中 局部坐标,世界坐标以及屏幕坐标,transform变换坐标以及 变换方向心得
- 将鼠标事件的设备坐标转换到世界坐标
- unity3d的世界坐标转化成屏幕坐标
- Unity3D的世界坐标转化成屏幕坐标
- 【最大独立集 && 有墙 && 无向图】HDU
- 三秒跳转第二次登录直接跳过
- 南宁杯CTF以及中科大CTF的一点总结
- 判断网络是否连接
- mybatis详解-(4)引入外部资源配置
- unity3d 怎么把鼠标坐标转成世界坐标
- 多进程服务器(python 版)
- RecyclerView源码详解(第三篇LayoutManager源码详解)
- 这或许才是帆软成为国内第一的BI公司的真正秘诀
- hive2.1.1安装部署
- ofbiz总结——查询实体时关于orderBy值的格式问题
- 为什么Cloudera要创建Hadoop安全组件Sentry?
- linux 杀死进程
- 天天学Linux命令45--ss命令