Files
2026-05-03 14:06:26 +08:00

14 lines
951 B
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
### 1.在屏幕坐标转换为世界坐标的过程中,Z轴不同应该如何处理
在2D游戏中,我们的摄像机Z坐标和场景的坐标一般是不同的,比如摄像机Z坐标为-10,场景坐标为0,那么如过我们在坐标转换的过程中,不特意的设置Z轴将产生一些问题.
比如
```
Vector3 screenPos = new(Input.mousePosition.x, Input.mousePosition.y, 0);
            Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);
```
上述代码可以在单击左键的时候进行坐标转换,但是我们传入的z轴为0,此时我们转换为世界坐标,他的z轴为-10.
因为我们的摄像机坐标为-10,传入0相当于使用摄像机的坐标.如过我们想让我们的坐标在场景当中,也就是0应该怎么办呢?
我们将z传入为10,也就是将屏幕坐标往z轴正方向移动10个单位,这时候获得的世界坐标z就是0.
### 2.Unity当中的Physics 2D raycaster组件作用和原理