Recenty started following a Unity tutorial and the script for the character controller is like this:
Vector2 inputVector = new Vector2(0, 0);
if (Input.GetKey(KeyCode.W)) {
inputVector.y = +1;
}
if (Input.GetKey(KeyCode.S)) {
inputVector.y = -1;
}
if (Input.GetKey(KeyCode.A)) {
inputVector.x = -1;
}
if (Input.GetKey(KeyCode.D)) {
inputVector.x = +1;
}
inputVector = inputVector.normalized;
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
transform.position += moveDir;
Debug.Log(inputVector);
I understand that ‘0f’ is so 0 is registered as a float rather than an integer but why is this needed in the Vector3 and not the Vector2 even though both of them require floats?
Thanks,
RandomCodeEnjoyer