Ejemplo n.º 1
0
 // return the next track
 public Track NextTrack()
 {
     if (Tracks.Count > 0)
     {
         return(Tracks.Dequeue());
     }
     return(null);
 }
Ejemplo n.º 2
0
 //Get the next track if there is one
 public Track NextTrack()
 {
     if (Tracks.Count != 0)
     {
         return(Tracks.Dequeue());
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
 public void FollowTrack()
 {
     if (!following && Tracks.Count > 0)
     {
         following  = true;
         index      = 0;
         track      = Tracks.Dequeue();
         matchSpeed = MatchSpeeds.Dequeue();
         track.TryCalculate();
         StartCoroutine(FollowTrackCoroutine());
     }
 }
Ejemplo n.º 4
0
    private IEnumerator FollowTrackCoroutine()
    {
        while (true)
        {
            float sprintModifier = 1;
            if (matchSpeed)
            {
                float playerTargetSpeed = (PlayerInfo.MovementManager.CurrentPercentileSpeed);
                sprintModifier = (playerTargetSpeed > 1) ? playerTargetSpeed : 1;
            }

            Vector3 currentPosition     = transform.position;
            Vector3 targetPosition      = track.Waypoints[index].position;
            Vector3 incrementedPosition = Vector3.MoveTowards(currentPosition, targetPosition, track.Waypoints[index].speed * sprintModifier * Time.deltaTime);
            transform.position = incrementedPosition;

            Quaternion currentRotation     = transform.rotation;
            Quaternion targetRotation      = track.Waypoints[index].rotation;
            Quaternion incrementedRotation = Quaternion.RotateTowards(currentRotation, targetRotation, track.Waypoints[index].rotationSpeed * sprintModifier * Time.deltaTime);
            transform.rotation = incrementedRotation;

            if (Vector3.Distance(currentPosition, targetPosition) < 0.05f)
            {
                endWaitTimer = 0;
                if (track.Waypoints[index].endWaitTime > 0)
                {
                    while (true)
                    {
                        sprintModifier = 1;
                        if (matchSpeed)
                        {
                            float playerTargetSpeed = (PlayerInfo.MovementManager.CurrentPercentileSpeed);
                            sprintModifier = (playerTargetSpeed > 1) ? playerTargetSpeed : 1;
                        }

                        endWaitTimer += Time.deltaTime * sprintModifier;
                        Quaternion currentEndRotation     = transform.rotation;
                        Quaternion targetEndRotation      = track.Waypoints[index].rotation;
                        Quaternion incrementedEndRotation = Quaternion.RotateTowards(currentEndRotation, targetEndRotation, track.Waypoints[index].rotationSpeed * sprintModifier * Time.deltaTime);
                        transform.rotation = incrementedEndRotation;
                        if (endWaitTimer >= track.Waypoints[index].endWaitTime)
                        {
                            break;
                        }
                        else
                        {
                            yield return(new WaitForEndOfFrame());
                        }
                    }
                }

                index++;

                if (index == track.Waypoints.Length)
                {
                    track.EndEvents.Invoke();

                    if (Tracks.Count > 0)
                    {
                        index      = 0;
                        track      = Tracks.Dequeue();
                        matchSpeed = MatchSpeeds.Dequeue();
                        track.TryCalculate();
                    }
                    else
                    {
                        following = false;
                        break;
                    }
                }
            }

            yield return(new WaitForEndOfFrame());
        }
    }