예제 #1
0
        public override void Update(float delta)
        {
            Vector3 distance = target - letter.transform.position;

            distance.y = 0;

            if (distance.sqrMagnitude < 0.05f)
            {
                // Face Camera!
                movement.LerpLookAt(Camera.main.transform.position, 8 * delta);
            }
            else
            {
                movement.MoveAmount(distance.normalized * speed * delta);
                movement.LerpLookAt(target, 4 * delta);

                distance   = target - letter.transform.position;
                distance.y = 0;

                if (distance.sqrMagnitude < 0.05f)
                {
                    letter.gameObject.GetComponent <LivingLetterController>().SetState(LLAnimationStates.LL_idle);
                }
            }
        }
        public override void Update(float delta)
        {
            // Scare neighbourhood
            near.Clear();
            letter.crowd.GetNearLetters(near, letter.transform.position, 5.0f);
            for (int i = 0, count = near.Count; i < count; ++i)
            {
                near[i].Scare(letter.transform.position, 2);
            }

            // Face Camera!
            movement.LerpLookAt(Camera.main.transform.position, 8 * delta);
        }
예제 #3
0
        public override void Update(float delta)
        {
            // Stay scared if danger is near
            if (Vector3.Distance(letter.transform.position, letter.antura.transform.position) < 15.0f)
            {
                ScaredDuration = 3;
                ScareSource    = letter.antura.transform.position;
            }
            else if (Vector3.Distance(letter.transform.position, ScareSource) > 7.0f)
            {
                scaredTimer = Mathf.Min(0.5f, scaredTimer);
            }

            scaredTimer -= delta;

            Vector3 dropPosition      = letter.walkableArea.focusPosition.position;
            Vector3 dropDistance      = dropPosition - letter.transform.position;
            bool    nearDropContainer = dropDistance.magnitude < 10;

            bool isOutsideWalkingPath = Vector3.Distance(
                letter.transform.position,
                letter.walkableArea.GetNearestPoint(letter.transform.position, true)
                ) > 6.0f;

            if (isOutsideWalkingPath && !nearDropContainer)
            {
                scaredTimer = Mathf.Min(0.1f, scaredTimer);
            }

            if (scaredTimer <= 0)
            {
                letter.SetCurrentState(letter.WalkingState);
                return;
            }

            // Run-away from danger!
            Vector3 runDirection = letter.transform.position - ScareSource;

            runDirection.y = 0;
            runDirection.Normalize();

            if (nearDropContainer)
            {
                runDirection = Vector3.Cross(letter.walkableArea.focusPosition.forward, Vector3.up).normalized;
            }

            movement.MoveAmount(runDirection * SCARED_RUN_SPEED * delta);
            movement.LerpLookAt(letter.transform.position + runDirection, 4 * delta);
        }
        public override void Update(float delta)
        {
            Vector3 distance = target - letter.transform.position;

            distance.y = 0;

            movement.MoveAmount(distance.normalized * speed * delta);
            movement.LerpLookAt(target, 4 * delta);

            timer -= delta;

            if (timer < 0 || distance.sqrMagnitude < 0.05f)
            {
                letter.SetCurrentState(letter.IdleState);
            }

            // if stuck for too long, change direction
            float avgSpeed = Vector3.Distance(letter.transform.position, lastPosition) / delta;

            if (avgSpeed < 0.5f * speed)
            {
                stuckTimer -= Time.deltaTime;
            }
            else
            {
                stuckTimer = STUCK_THRESHOLD;
            }

            if (stuckTimer <= 0)
            {
                // change direction
                target     = letter.crowd.walkableArea.GetNearestPoint(letter.transform.position - 2 * distance, true);
                stuckTimer = STUCK_THRESHOLD;
            }

            lastPosition = letter.transform.position;

#if UNITY_EDITOR
            Debug.DrawLine(letter.transform.position, target);
#endif
        }