// Update is called once per frame void Update() { // iff scoping half the sensitivity if (isHunter) { if (hunterRef.GetIsScoped()) { mouseMoveValue = scopeSensitivity; } } else { mouseMoveValue = mouseSensitivity; } float mouseX = Input.GetAxis("Mouse X") * mouseMoveValue * Time.deltaTime; float mouseY = Input.GetAxis("Mouse Y") * mouseMoveValue * Time.deltaTime; //Debug.Log("Mouse values. mouseX = " + mouseX + ". mouseY = " + mouseY); xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, minLookUp, maxLookUp); transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); playerBody.Rotate(Vector3.up * mouseX); }
// Update is called once per frame void Update() { if (!hasAuthority) { return; } isRunning = false; isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundLayer); if (isGrounded && velocity.y < 0) { velocity.y = -2; } float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); Vector3 move = transform.right * x + transform.forward * z; // crouched input if (Input.GetKeyDown(KeyCode.LeftControl) && hunterRef == null) { isCrouched = !isCrouched; if (isCrouched) { headObject.transform.localPosition = crouchHeadPosition.localPosition; nanim.animator.SetBool("isCrouched", true); } else { headObject.transform.localPosition = standingHeadPosition.localPosition; nanim.animator.SetBool("isCrouched", false); } } if (isCrouched || (hunterRef != null && hunterRef.GetIsScoped())) { controller.Move(move * crouchingSpeed * Time.deltaTime); // make sure to switch colliders to smaller one. } else { // the player is holding the running button down or not if (Input.GetKey(KeyCode.LeftShift)) // running { if (isGrounded) {// running on the ground controller.Move(move * runningSpeed * Time.deltaTime); } else {// running in the air controller.Move(move * crouchingSpeed * Time.deltaTime); } isRunning = true; } else { // not running if (isGrounded) { // not running on ground controller.Move(move * speed * Time.deltaTime); } else {// not running in air controller.Move(move * crouchingSpeed * Time.deltaTime); } } } if (Input.GetButtonDown("Jump") && isGrounded && !isCrouched) { velocity.y = Mathf.Sqrt(jumpHeight * -jumpForce * gravity); nanim.SetTrigger("Jump"); StartCoroutine(ResetJumpTrigger()); } if (x != 0f || z != 0f) { // character is moving Debug.Log("Character is moving"); if (isRunning) { nanim.animator.SetFloat("speed", 1f); } else { nanim.animator.SetFloat("speed", 0.5f); } } else { nanim.animator.SetFloat("speed", 0f); } velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); }