I am doing camera navigation (Movement/Rotation) on Update event in this way:
void UpdateMovement()
{
bool accelerate = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
moveDirection =
new
Vector3(
Input.GetAxisRaw("Horizontal") * moveSpeed,
0,
Input.GetAxisRaw("Vertical") * moveSpeed);
//moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0, Input.GetAxis("Vertical") * moveSpeed);
moveDirection = transform.TransformDirection(moveDirection);
if (Input.GetButton("Up"))
{
moveDirection.y += moveSpeed;
}
else if (Input.GetButton("Down"))
{
moveDirection.y -= moveSpeed;
}
if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
{
moveDirection.y = moveDirection.y + scrollSpeed;
}
else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0)
{
moveDirection.y = moveDirection.y - scrollSpeed;
}
moveDirection *= (accelerate ? speed : moveSpeed);
controller.Move(moveDirection * Time.deltaTime);
}
void UpdateRotation()
{
if (!Input.GetMouseButton(1))
return;
rotationX += Input.GetAxis("Mouse X") * lookSpeed;
rotationY += Input.GetAxis("Mouse Y") * lookSpeed;
rotationY = Mathf.Clamp(rotationY, -90, 90);
rotationZ = Input.GetAxis("Mouse ScrollWheel");
transform.localRotation = Quaternion.AngleAxis(rotationZ, Vector3.forward);
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
}
All working fine but the problem on WebGL canvas when I rotate the camera using mouse and comes out of the bound of WebGl canvas meanwhile, I also continuously press horizontal or vertical key, then release input key doesn't work. Remember I logged the key[Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")] input and found that it is not reset to zero on release.
Debug.Log("Hr GetAxisRaw : " + Input.GetAxisRaw("Horizontal"));
Debug.Log("Vertical : " + Input.GetAxisRaw("Vertical"));
Normally when I don't use camera rotation using mouse and during this time, when i release the horizontal/vertical key, it works fine. I was previously using Input.GetAxis now i am using Input.GetAxisRaw but the problem is same.
