void Work() { currWorkShift -= Time.deltaTime; if (!closestObject) { closestObject = myInteractor.FindClosestObjectWithTag("interactiveEnvironment", false); } Vector3 relativePos = closestObject.transform.position - transform.position; transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativePos, Vector3.up), Time.deltaTime * 30f); if (myInteractor.minimumDistance < Vector3.Distance(transform.position, closestObject.transform.position)) { transform.Translate(Vector3.forward * Time.deltaTime * speed); if (animator) { animator.SetBool("interacting", false); } if (animator) { animator.SetBool("walking", true); } } else { myInteractor.InteractWithNearbySurroudings(); if (!myInteractor.interactionInProgress) { closestObject = null; if (animator) { animator.SetBool("interacting", false); } } else { if (animator) { animator.SetBool("interacting", true); } } //if (animator) // animator.SetBool("walking", false); } if (currWorkShift <= 0) { myInteractor.CancelInteraction(); if (animator) { animator.SetBool("interacting", false); } currRestBreak = restTime; currState = ActivityState.resting; closestObject = null; } }
// Update is called once per frame void Update() { float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); float speedToUse = (rakeController && rakeController.IsRaking()) ? rakingSpeed : speed; if (isTryingToInteract) { speedToUse = 0.0f; } //transform.Translate(speedToUse * horizontalInput*Time.deltaTime, 0, speedToUse * verticalInput*Time.deltaTime); float ySpeed = charController.velocity.y; ySpeed += Physics.gravity.y * Time.deltaTime; float yOffset = charController.isGrounded?0:ySpeed * Time.deltaTime; charController.Move(new Vector3(speedToUse * horizontalInput * Time.deltaTime, yOffset, speedToUse * verticalInput * Time.deltaTime)); if ((horizontalInput != 0 || verticalInput != 0) && speedToUse > 0.0f) { animator.SetBool("moving", true); float xzSpeed = (new Vector2(speedToUse * horizontalInput, speedToUse * verticalInput)).magnitude; animator.SetFloat("walk_speed", xzSpeed * .75f); playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, Quaternion.LookRotation( new Vector3(speed * verticalInput, 0, -speed * horizontalInput)), Time.deltaTime * 30f); } else { animator.SetBool("moving", false); } if (Input.GetButton("Interact")) { myInteractor.InteractWithNearbySurroudings(); isTryingToInteract = true; animator.SetBool("interacting", true); } else { if (myInteractor.interactionInProgress) { myInteractor.CancelInteraction(); } isTryingToInteract = false; animator.SetBool("interacting", false); } if (Input.GetButtonDown("Taking")) { GameObject item = myInteractor.TakeNearbyObject(); if (item != null) { AddToInventory(item); audioSource.PlayOneShot(pickupAudio, 0.25F); } else { // no items to take PlaceFromInventory(); } } }