unity Vector api
Vector3.magnitude 和 Vector3.sqrMagnitude用法
Vector3.magnitude --> 把vertor數字平方相加在開根號
Vector3.sqrMagnitude-->把vertor數字平方
------------------------------------------------------------------------------------------------------
假設 Vector3(2,3,4)-->>Vector3.magnitude =sqrt(x^x+y^y+z^z)
=sqrt(2*2+3*3+4*4)=sqrt(29)=5.385165
用來計算距離很好用
Vector3.sqrMagnitude=( x^x+y^y+z^z)=(29)
sqrMagnitude不開根號,速度上sqrMagnitude更快效能好
---------------------------------------------------------------------------------------------------
Vector3.forward =>Vector3(0, 0, 1).
Vector3.back =>Vector3(0, 0, -1).
Vector3.down =>Vector3(0, -1, 0).
Vector3.left =>Vector3(-1, 0, 0).
Vector3.normalized=>Vector3(1, 1, 1).
No comments:
Post a Comment