Example #1
0
        /// <summary>
        /// Generate grid using grid size and separation space settings
        /// </summary>
        private void GenerateGrid()
        {
            if (m_FlowFieldZonePrefab != null)
            {
                int sumIndex = 0;
                for (int i = 0; i < m_GridSize.x; i++)
                {
                    for (int j = 0; j < m_GridSize.y; j++)
                    {
                        for (int k = 0; k < m_GridSize.z; k++)
                        {
                            // Instantiate zone
                            SteeringFlowFieldZone zone = Instantiate(m_FlowFieldZonePrefab);
                            zone.transform.position = transform.position + new Vector3(i * m_SeparationSpace, j * m_SeparationSpace, k * m_SeparationSpace);
                            zone.transform.parent   = transform;

                            // Set zone direction
                            Vector3 direction = GetDirection(sumIndex, i, j, k);
                            zone.Direction = direction;

                            sumIndex++;
                            m_PerlinY = k * 0.1f;
                        }
                    }
                    m_PerlinX = i * 0.1f;
                }
            }
        }
        /// <summary>
        /// Flow field following behavior
        /// </summary>
        public override void PerformSteeringBehavior()
        {
            if (SteeringCore == null)
            {
                return;
            }

            // Get flow field zone containing character
            SteeringFlowFieldZone flowFieldZone = GetFlowFieldZoneEntered();

            if (flowFieldZone != null)
            {
                // Calculate desired velocity
                m_DesiredVelocity = (flowFieldZone.Direction).normalized * SteeringCore.MaxSpeed;

                // Calculate steering force
                SteeringForce = m_DesiredVelocity - SteeringCore.Velocity;
            }
            else
            {
                SteeringForce = Vector3.zero;
            }
        }