예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (m_bArrived)
        {
            gameObject.rigidbody2D.velocity = Vector2.zero;
        }
        else if (m_path != null)
        {
#if fasle
            // Compute the seek position (the position we are traveling toward)
            float   currentDistAlongPath = m_path.MapPointToPathDistance(transform.position);
            float   futureDist           = currentDistAlongPath + m_lookAheadDistance;
            Vector3 seekPos = m_path.MapPathDistanceToPoint(futureDist);

            // Set the height of the seek pos, based on the terrain.
            SimpleAI.ConvertUtils.SetThirdValue(ref seekPos, m_pathTerrain.GetTerrainHeight(seekPos));

            // Determine the new velocity
            Vector3 newVelocity = Vector3.zero;

            Vector3 destPos = (m_path.Points[m_path.Points.Length - 1]);
            SimpleAI.ConvertUtils.SetThirdValue(ref destPos, m_pathTerrain.GetTerrainHeight(destPos));

            Vector3 currentFloorPosition = transform.position;
            SimpleAI.ConvertUtils.SetThirdValue(ref currentFloorPosition, m_pathTerrain.GetTerrainHeight(currentFloorPosition));
            float distToDestPos = Vector3.Distance(currentFloorPosition, destPos);
            if (distToDestPos <= m_arrivalDistance)
            {
                if (!m_bArrived)
                {
                    // No velocity if we are at our destination
                    newVelocity = Vector3.zero;
                    OnArrived();
                }
            }
            else
            {
                newVelocity = ComputeArrivalVelocity(seekPos, destPos, currentFloorPosition, rigidbody.velocity);
            }

            rigidbody.velocity = newVelocity;
#else
            //
            if (Vector3.Distance(m_seekPos, transform.position) < m_arrivalDistance)
            {
                if (m_path_index == m_path.PointCount)
                {
                    OnArrived();
                    return;
                }
                m_seekPos = m_path.Points[m_path_index++];
                m_pathStep.SetPos(transform.position, m_seekPos);
            }
            transform.position = m_pathStep.VectorByStep(Time.deltaTime * m_accelerationRate);
#endif
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (m_bArrived)
        {
            //gameObject.rigidbody.velocity = Vector3.zero;
            m_wantedVelocity = Vector3.zero;
        }
        else if (m_path != null)
        {
            // Compute the seek position (the position we are traveling toward)
            float   currentDistAlongPath = m_path.MapPointToPathDistance(transform.position);
            float   futureDist           = currentDistAlongPath + m_lookAheadDistance;
            Vector3 seekPos = m_path.MapPathDistanceToPoint(futureDist);

            // Set the height of the seek pos, based on the terrain.
            seekPos.y = m_pathTerrain.GetTerrainHeight(seekPos);

            // Determine the new velocity
            Vector3 newVelocity = Vector3.zero;
            Vector3 destPos     = (m_path.Points[m_path.Points.Length - 1]);
            destPos.y = m_pathTerrain.GetTerrainHeight(destPos);
            Vector3 currentFloorPosition = transform.position;
            currentFloorPosition.y = m_pathTerrain.GetTerrainHeight(currentFloorPosition);
            float distToDestPos = Vector3.Distance(currentFloorPosition, destPos);
            if (distToDestPos <= m_arrivalDistance)
            {
                if (!m_bArrived)
                {
                    // No velocity if we are at our destination
                    newVelocity = Vector3.zero;
                    OnArrived();
                }
            }
            else
            {
                newVelocity = ComputeArrivalVelocity(seekPos, destPos, currentFloorPosition, m_wantedVelocity);//rigidbody.velocity);
            }

            //rigidbody.velocity = newVelocity;
            m_wantedVelocity = newVelocity;
        }
    }