// Update is called once per frame void Update() { if (totalFear > fearThreshold) { animator.SetInteger("Shookiness", 1); } if (state == VisitorState.Idle) { GetNewInterestItem(); if (currentInterestItem != null) { agent.destination = currentInterestItem.GetStandPosition(); state = VisitorState.MovingToObserve; agent.speed = baseSpeed; } } else if (state == VisitorState.MovingToObserve) { if (!agent.pathPending && agent.remainingDistance < 0.5f) { agent.ResetPath(); state = VisitorState.Observing; startedObservingTimestamp = Time.time; } agent.speed = baseSpeed; } else if (state == VisitorState.Observing) { transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(currentInterestItem.GetLookDirection(), Vector3.up), 0.2f); if (Time.time - startedObservingTimestamp > interestDuration) { GetNewInterestItem(); agent.destination = currentInterestItem.GetStandPosition(); state = VisitorState.MovingToObserve; } agent.speed = baseSpeed; } else if (state == VisitorState.FleeingRoom) { if (!agent.pathPending && agent.remainingDistance < 0.5f) { agent.ResetPath(); state = VisitorState.Idle; } agent.speed = baseSpeed * 1.5f; animator.SetInteger("Shookiness", 2); } else if (state == VisitorState.FleeingBuilding) { agent.ResetPath(); rb.isKinematic = false; Vector3 direction = Vector3.zero; direction += -visitorScript.LocalGradient().normalized; if (!player.GetComponent <PlayerInvisibility>().isInvisible) { Vector3 playerOffset = transform.position - player.transform.position; direction += playerOffset.normalized; } Vector3 exitOffset = exit.position - transform.position; direction += exitOffset.normalized * 2.5f; Debug.Log(direction); //rb.AddForce(force); rb.velocity = direction.normalized * baseSpeed; animator.SetInteger("Shookiness", 2); if ((transform.position - exit.position).magnitude < 5f) { Destroy(gameObject); } //if (!agent.pathPending && agent.remainingDistance < 0.5f) //{ // agent.ResetPath(); // Destroy(gameObject); //} //agent.speed = baseSpeed * 1.5f; } }