Ejemplo n.º 1
0
        void Update()
        {
            // If we have landed, stop the animation.
            if (m_flockMovement.IsLanded() && Time.time > m_flockMovement.LandTime + 2)
            {
                m_animation.Play("Idle");
            }
            else             // Otherwise, speed up the animation based on speed.
            {
                m_animationState.speed = .1f
                                         + (1 -
                                            (m_flockMovement.Velocity.sqrMagnitude
                                             / m_flockMovement.Parameters.maxSpeed.GetValueSqr())
                                            ) * 2;
            }

            // Face our movement.
            if (!m_flockMovement.IsLanded())
            {
                transform.LookAt(
                    m_flockMovement.CachedTransform.position
                    + m_flockMovement.Velocity
                    );
            }
            else
            {
                transform.rotation = Quaternion.Lerp(
                    transform.rotation,
                    Quaternion.LookRotation(m_flockMovement.LandDirection),
                    Time.deltaTime
                    );
            }
        }
Ejemplo n.º 2
0
        void OnDrawGizmos()
        {
            Gizmos.color = m_flockMovement.IsLanded()
                                ? Color.yellow : new Color(1.0f, 0.0f, 1.0f, 0.1f);

            if (m_flockMovement.LandingPosition != null)
            {
                Gizmos.DrawLine(
                    transform.position,
                    m_flockMovement.LandingPosition.GetPosition()
                    );
            }
            else if (m_flockMovement.Target)
            {
                Gizmos.DrawLine(transform.position, m_flockMovement.Target.position);
            }

            if (m_flockMovement.IsLanded())
            {
                Gizmos.color = Color.green;
                Gizmos.DrawLine(
                    m_flockMovement.GoalPosition,
                    m_flockMovement.GoalPosition + m_flockMovement.LandDirection * 3
                    );
            }

            Gizmos.color = new Color(1.0f, 1.0f, 1.0f, .5f);

            Vector3 vel   = m_flockMovement.Velocity;
            float   speed = m_flockMovement.Velocity.magnitude;

            if (speed < 1)
            {
                vel *= 1 / speed;
            }
            Gizmos.DrawLine(transform.position, transform.position + vel * 0.1f);

            Gizmos.color = Color.white;
        }