Esempio n. 1
0
    public void generatePath()
    {
        // Reset the line renderer
        lineRenderer.positionCount = 0;

        if (numWaypoints > 1)
        {
            // Reset the DLL generator
            rb_script.resetGenerator();

            // First waypoint in the generator will be the robot starting position
            rb_script.addWaypoint(waypointList[0].GetComponent <Transform>().position.x, waypointList[0].GetComponent <Transform>().position.y, 0);

            // Add all subsequent waypoints to the generator, adjusted based on the x and y offset of the starting position
            for (int i = 1; i < numWaypoints; i++)
            {
                rb_script.addWaypoint(waypointList[i].GetComponent <Transform>().position.x,
                                      waypointList[i].GetComponent <Transform>().position.y,
                                      waypointList[i].GetComponent <ObjectDrag>().angle);
            }

            // Generate the path
            rb_script.generatePath();

            // Retrieve the path from the generator
            float[,] path;
            path = rb_script.getPath();

            lineRenderer.positionCount = path.GetLength(0);
            rb_script.path_segments    = path.GetLength(0);

            // Use the line renderer to display the generated path
            for (int i = 0; i < path.GetLength(0); i++)
            {
                lineRenderer.SetPosition(i, new Vector3(path[i, 0],
                                                        path[i, 1],
                                                        10f));
            }
        }
    }