Vector3 newVelocity = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f) * Time.deltaTime;
newVelocity.Normalize();
newVelocity.Set(newVelocity.x * speed, newVelocity.y * speed, 0f);
speed๋ ๋ฐ์์ย ํ๋กํธ๋ก ์ ์ธ๋์์ด
์ฌ๊ธฐ์ ๋ง์ง๋ง์ speed๊ณฑํด์ฃผ๋๊ฑธ ๋ฒกํฐ.set๊ฐ ์๋๋ผ ๋ฒกํฐ*speed ๋ก๋ ๋ชปํ๋๊ฑฐ์ผ? ๋ณด๋๊น new ์ด๋๋๋ฌธ์ ์๋๋๊ฑฐ๊ฐ๋๋ฐ
set๊ฐ์๋๋ผ ๊ทธ๋ฅ ๋ฒกํฐ์ speed๋ฅผ ๊ณฑํด๋ฒ๋ฆฌ๋๋ฐฉ๋ฒ์ ๋ญ๊ฐ์์ด?
newVelocity = newVelocity * speed; ํ๋ฉด ๋์ง ์์๊น? ํท๊ฐ๋ฆฌ๋ค ใ
์ค ๋ด๊ฐ๋นก๋๊ฐ๋ฆฌ์ฟ๋ค
์ ๋ํฐ๊ฐ ๋๋ฌด๋ค์์์ ํด์ค๋ค๋์๊ฐ์ ํฐ๊ฑธ ๋นผ๋จน์๊ตฌ๋
๊ฐ๋ ์ฑ ๊ฐ ์น์ฐฝ ๋ด๋๋ค ใ ใ ์์ ํ์ฒ๋ผ ํ๊ณ newVel = newVel.normalized * speed; newVel.z =0f; ํ๋๊ฑฐ๋ ใ ใ
์์ ํ์ฒ๋ผ ํ๊ณ ๋ ์ญ์
z๋ ์๋ 0์ธ๋ฐ 0์ ๋๊ณฑํ๋์ด์ ๋ ๋ญ์?
์ญ์ ๋ง์ดํด๋ณธ์ฌ๋์ด ์ค์ด๋๊ฑฐ ๋์ํ๋ค
์ฝ๋ ๋ ๋์ถฉ ๋ดค๋ค. newVal.z = 0; ์ํด๋ ๋จ.
์ํ๋๊ฒ ์๋๋ผ ์ ์ด์ Vector์ ๊ฐ๋ณ๋ก ๊ฐ ๋ชป๋ฃ์
์์ฃ๋ ๋ญ ํ์๋ฆฌ ์จ๋จ๋ Vector3์ ์ ๊ฐ๋ณ๋ก ๊ฐ์ ๋ชป๋ฃ์ด ๋ธ ์ ์ ใ
์๋ชป๋ดค์์๋ ์์ง ์ ์์ํด
๋ฏธ์
Vector3 directionalInput = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0f); Vector3 newVelocity = directionalInput.normalized * speed * Time.deltaTime;
์ฝ๋ ๊ฐ๋ ์ฑ ์ฌ๊ฐํ๋ฐ