Last active
November 20, 2019 07:12
-
-
Save TheAllenChou/9a126c74a32e21ae606c124fabd0783a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 inputVec = Vector3.zero; | |
if (Input.GetKey(KeyCode.UpArrow)) | |
inputVec += Vector3.up; | |
if (Input.GetKey(KeyCode.DownArrow)) | |
inputVec += Vector3.down; | |
if (Input.GetKey(KeyCode.LeftArrow)) | |
inputVec += Vector3.left; | |
if (Input.GetKey(KeyCode.RightArrow)) | |
inputVec += Vector3.right; | |
Vector3 inputMagSqr = inputVec.sqrMagnitude; | |
Vector3 inputDir = | |
inputMagSqr > Mathf.Epsilon | |
? inputVec / Mathf.Sqrt(inputMagSqr) | |
: Vector3.zero; | |
Vector3 moveVec = speed * inputDir * Time.deltaTime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment