Player 이동 연습2(정규화 벡터)
2023. 8. 18.

키보드 입력이 잘 되는지 찍어보았다.

x와 z값이 출력된다.

 

코드를 수정해 비교

moveDir와 new Vector3(h,0,v)는 같은 값을 출력하지만

moveDir는 연산을 해준 것을 변수에 담은 것이고, 후자는 벡터에 넣어 찍어본 것이다.

 

즉 전자는 두 벡터를 더하는 연산으로 이는 새로운 벡터가 생겨나는 것인데,

새로운 벡터에 값을 넣어주는 것과 같은 의미가 되는 것이다.

화살표를 화면에 그려서 비교해보려 한다.

 

https://gist.github.com/MatthewMaker/5293052

 

DrawArrow.cs

GitHub Gist: instantly share code, notes, and snippets.

gist.github.com

우,상 키보드 동시에 누르면 대각선으로 화살표가 그려진다.

https://docs.unity3d.com/ScriptReference/Vector3-normalized.html

 

Unity - Scripting API: Vector3.normalized

When normalized, a vector keeps the same direction but its length is 1.0. Note that the current vector is unchanged and a new normalized vector is returned. If you want to normalize the current vector, use Normalize function. If the vector is too small to

docs.unity3d.com

대각선(상,우 등 동시에 누른것)일 때 출력/ 오른쪽 키보드 눌렀을 때 출력

 

Vector3.normalized를 하면 정규화된 벡터를 반환한다.

=> normalized를 이용하면 대각선으로 이동할 때에도 동일한 속도를 보장할 수 있다.

 

Time.deltaTime을 곱하지 않은 경우

 

myoskin