예제 #1
0
    // Update is called once per frame
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
        float   distance = path.GetDistance();
        Vector3 diff     = desiredPoint - transform.position;

        if (diff.magnitude < 1)
        {
            if (currentRatio >= 1)
            {
                currentRatio = 0;
            }
            else
            {
                currentRatio += ratio;
            }
            desiredPoint = path.CalcPositionByDistanceRatio(currentRatio);
            distance     = (new Vector3(desiredPoint.x, desiredPoint.y, desiredPoint.z) - move.transform.position).magnitude;
            NavMeshPath nerdPath = new NavMeshPath();
            agent.police.CalculatePath(desiredPoint, nerdPath);
            pathCorners = new Vector3[nerdPath.corners.Length];

            nerdPath.corners.CopyTo(pathCorners, 0);
        }
        seek.SetPathCorners(pathCorners);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (path != null)
        {
            Vector3 target = Vector3.zero;

            // TODO 2: Check if the tank is close enough to the desired point
            // If so, create a new point further ahead in the path
            target = path.CalcPositionByDistanceRatio(current_percentage);

            //float path_len = path.length;
            float distance = (target - transform.position).magnitude;

            if (distance < accuracy)
            {
                current_percentage += distance_ratio;
                if (current_percentage > 1.0f)
                {
                    current_percentage -= 1.0f;
                }
            }

            seek.Steer(target, priority);
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        ratio += ratio_increment * Time.deltaTime;

        move.SetMovementVelocity(math.CalcPositionByDistanceRatio(ratio) - move.aim.transform.position);

        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
    }
예제 #4
0
    void CalcPosition()
    {
        if (Vector3.Distance(transform.position, path.CalcPositionByDistanceRatio(ratio)) <= 0.1f)
        {
            /* if (timer.GetActive() != true)
             *   timer.StartTimer();*/

            // if (timer.GetSeconds() > 5)
            {
                timer.ResetTimer();
                pos    = path.CalcPositionByDistanceRatio(ratio);
                ratio += 0.1f;
            }
        }

        else
        {
            pos = path.CalcPositionByDistanceRatio(ratio);
        }
    }
예제 #5
0
 // Update is called once per frame
 void Update()
 {
     // TODO 1: Have a GameObject that follows the curve's path
     // Increase the ratio [0 to 1] and set the GameObject position to the respecive point in the curve
     if (currentRatio > 1.0f)
     {
         currentRatio = 0;
     }
     transform.position = path.CalcPositionByDistanceRatio(currentRatio);
     currentRatio      += step;
 }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (!stop)
        {
            currentRatio += 0.001f;
            if (currentRatio >= 1)
            {
                currentRatio = 0;
            }

            transform.position = path.CalcPositionByDistanceRatio(currentRatio);
        }
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        // TODO 3: Check if the tank is close enough to the desired point
        seek.Steer(closest_point);

        // If so, create a new point further ahead in the path
        if ((transform.position - closest_point).magnitude <= 0.1)
        {
            current_pos += 0.01f;
            if (current_pos >= 1)
            {
                current_pos = 0;
            }
            closest_point = path.CalcPositionByDistanceRatio(current_pos);
        }
    }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
        current_point    = path.CalcPositionByDistanceRatio(current_ratio);
        current_distance = current_point - transform.position;

        if (current_distance.magnitude < min_distance)
        {
            current_ratio += ratio_increment;
            if ((current_ratio) > 1.0f)
            {
                current_ratio = 0.0f;
            }
        }

        seek.Steer(current_point);
    }
예제 #9
0
    // Update is called once per frame
    void Update()
    {
        //increase distance

        if (ratio < 1.0f)
        {
            ratio += 0.1f * Time.deltaTime;
        }

        if (ratio >= 1.0f)
        {
            ratio = 0.0f;
        }

        //calculate position and tangent
        transform.position = path.CalcPositionByDistanceRatio(ratio);
        //this is a version for 3D. For 2D, comment this line and uncomment the next one
        //transform.rotation = Quaternion.LookRotation(tangent);
        //ObjectToMove.rotation = Quaternion.AngleAxis(Mathf.Atan2(tangent.y, tangent.x) * Mathf.Rad2Deg, Vector3.forward);
    }
예제 #10
0
    // Update is called once per frame
    void Update()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        Vector3 target = Vector3.zero;

        target = path.CalcPositionByDistanceRatio(current_percentage);
        float distance = (target - transform.position).magnitude;

        if (distance < accuracy)
        {
            current_percentage += distance_ratio;
            if (current_percentage >= 1.0f)
            {
                current_percentage = 0.0f;
            }
        }
        //Debug.Log(current_percentage);
        GetComponent <NavMeshAgent>().destination = target;
    }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        Vector3 direction = closest_point - transform.position;

        if (direction.magnitude < 0.05f)
        {
            current_ratio += ratio_increment;

            if (current_ratio > 1.0f)
            {
                current_ratio = 0.0f;
            }

            closest_point = path.CalcPositionByDistanceRatio(current_ratio);
        }
        else
        {
            this.transform.position += direction.normalized * 5 * Time.deltaTime;
        }
        //this.transform.Translate(direction.normalized * 5 * Time.deltaTime);
    }
예제 #12
0
    // Update is called once per frame
    void Update()
    {
        move.target.transform.position = closest_point;
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
        Vector3 position = closest_point - transform.position;

        if (position.magnitude < min_distance)
        {
            current_ratio += ratio_increment;
            if (current_ratio > 1.0f)
            {
                current_ratio = 0.0f;
            }

            closest_point = path.CalcPositionByDistanceRatio(current_ratio);
        }
        else
        {
            seek.Steer(closest_point);
        }
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path

        Vector3 position = closest_point - transform.position;

        if (position.magnitude < min_distance) // min distance to closest point
        {
            current_ratio += ratio_increment;  //increment ratio distance to reach 1 from range [0,1]

            if (current_ratio > 1.0f)          // if ratio distance reach 1, it becomes 0 to start again from initial point
            {
                current_ratio = 0.0f;
            }

            closest_point = path.CalcPositionByDistanceRatio(current_ratio); // Returns the position due current ratio
        }
        else
        {
            seek.Steer(closest_point);
        }
    }
예제 #14
0
    // Update is called once per frame
    void Update()
    {
        if (!move)
        {
            move = GetComponent <Move>();
        }
        else
        {
            if (Vector3.Distance(transform.position, closest_point) <= min_distance)
            {
                current_ratio += ratio_increment;
                if (current_ratio > 1)
                {
                    current_ratio = 0;
                }
                closest_point = path.CalcPositionByDistanceRatio(current_ratio);
            }

            seek.Steer(closest_point);
        }

        seek.Steer(closest_point);
    }
예제 #15
0
    // Update is called once per frame
    void Update()
    {
        if (path != null)
        {
            Vector3 target = Vector3.zero;

            target = path.CalcPositionByDistanceRatio(current_percentage);

            //float path_len = path.length;
            float distance = (target - transform.position).magnitude;

            if (distance < accuracy)
            {
                current_percentage += distance_ratio;
                if (current_percentage > 1.0f)
                {
                    current_percentage -= 1.0f;
                }
            }

            seek.Steer(target, priority);
        }
    }
예제 #16
0
    // Update is called once per frame
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path

        Vector3 position_in_curve = closet_point - transform.position;

        if (position_in_curve.magnitude < 0.05) // min distance to closet point center
        {
            range_distance += 0.05f;            //ratio distance

            if (range_distance > 1.0f)
            {
                range_distance = 0.0f;
            }

            closet_point = path.CalcPositionByDistanceRatio(range_distance);
        }
        else
        {
            seek.Steer(closet_point);
        }
    }
예제 #17
0
    void Update()
    {
        // TODO 2: Check if the tank is close enough to the desired point
        // If so, create a new point further ahead in the path
        Vector3 target         = closestPoint - transform.position;
        float   targetDistance = target.magnitude;

        if (targetDistance < minDistance)
        {
            Debug.Log("New point!");

            accumulatedDistanceRatio += distanceRatio;

            if (accumulatedDistanceRatio > 1.0f)
            {
                accumulatedDistanceRatio = 0.0f;
            }

            closestPoint = path.CalcPositionByDistanceRatio(accumulatedDistanceRatio);
        }

        seek.Steer(closestPoint);
    }
예제 #18
0
 // Start is called before the first frame update
 void Start()
 {
     this.transform.position = path.CalcPositionByDistanceRatio(sph_position);
 }