Ejemplo n.º 1
0
    private Vector3 getStudentPosition(int studentIndex)
    {
        float   loc       = studentLocations[studentIndex];
        int     pathIndex = path.GetIndexAtDistance(loc);
        Vector3 start     = path.GetPoint(pathIndex);
        Vector3 end       = path.GetPoint(pathIndex + 1);

        Vector3 studentPos = path.GetPositonAlongPath(loc);

        float dist = 0.5f + Random.value;

        if (Random.value > 0.5)
        {
            dist = -1 * dist;
        }

        Vector3 diff = end - start;

        Debug.Log("Pos: " + studentPos);

        if (diff.x == 0)
        {
            studentPos.x = studentPos.x + dist;
        }
        else if (diff.z == 0)
        {
            studentPos.z = studentPos.z + dist;
        }
        else
        {
            float direction = diff.x / diff.z;

            studentPos = new Vector3(studentPos.x + (1 / direction) * dist, studentPos.y, studentPos.z + (direction) * dist);
        }

        return(studentPos);
    }