Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        curSpeed = speed * Time.deltaTime;

        targetPoint = path.GetPoint(curPathIndex);

        if (Vector3.Distance(transform.position, targetPoint) < path.Radius)
        {
            if (curPathIndex < pathLength - 1)
            {
                curPathIndex++;
            }
            else if (isLooping)
            {
                curPathIndex = 0;
            }
            else
            {
                return;
            }
        }

        if (curPathIndex >= pathLength)
        {
            Debug.Log("impossible curPathIndex" + curPathIndex);
            return;
        }

        if (curPathIndex >= pathLength - 1 && !isLooping)
        {
            velocity += Steer(targetPoint, true);
        }
        else
        {
            velocity += Steer(targetPoint);
        }

        Debug.DrawLine(transform.position, transform.position + velocity * 10, Color.green);
        transform.position += velocity;
//		transform.LookAt (velocity + transform.position);
        transform.rotation = Quaternion.LookRotation(velocity);
    }