【发布时间】:2021-05-05 07:56:44
【问题描述】:
我试图向鼠标的方向射击子弹。但是鼠标离我的枪越近,子弹走的越慢。所以我想我应该标准化我的向量:
Vector3 shootDirection = (mousePosition - shootpoint.transform.position);
shootDirection.Normalize();
据我所知,在对向量进行归一化后,它的 x 和 y 将遵循勾股定理:
x^2 + y^2 = 1
但是,如果我在规范化后调试矢量坐标,我会得到:
0,1915651 0,1933651
0,5729401 0,4919207
这显然不符合规则。有什么帮助吗?
【问题讨论】:
-
你是如何打印的?因为
Vector3有 3 个组件 ... -
debug.log(shootDirection.x + " " + shootDirection.y)
-
是的,如前所述..
Vector3有 x,y,z,这些加起来是 1 ...也许你想要Vector2?
标签: c# unity3d game-development