void FixedUpdate()
    {
        if (path == null)
        {
            return;
        }

        distance += speed * Time.deltaTime;

        if (distance > path.GetTotalDistance())
        {
            distance = 0;
        }


        Vector3 position = path.GetPositonAlongPath(distance);
        Vector3 ahead    = path.GetPositonAlongPath(distance + amountToLookAhead);

        railCamera.transform.position = position;
        railCamera.transform.LookAt(ahead);
    }
Example #2
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);
    }