Exemple #1
0
        //<summary>
        //Resets agent posiiton if they crash using its current Next checkpoint Index
        //If randomize is true it resets the plane at  a random checkpoint
        //</summary>
        public void ResetAgentPosition(AircraftAgent agent, bool randomize = false)
        {
            if (randomize)
            {
                //Picka a new next checkpoint at  random
                agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
            }

            //Set start position to the previous checkpoint
            int previousCheckpointIndex = agent.NextCheckpointIndex - 1;

            if (previousCheckpointIndex == -1)
            {
                previousCheckpointIndex = Checkpoints.Count - 1;
            }

            float startPosition = racePath.FromPathNativeUnits(previousCheckpointIndex, CinemachinePathBase.PositionUnits.PathUnits);

            //Convert the position on the race path to a position in 3d space;
            Vector3 basePosition = racePath.EvaluatePosition(startPosition);

            //Get orientation at that position oin the race path
            Quaternion orientation = racePath.EvaluateOrientation(startPosition);

            //Calculate a horizontal offset so that agents are spread out
            //Calcualtes based on number of agents and current agent how far away another agent needs to spawn
            //Make it random so that the game isnt exactly the same
            Vector3 positionOffset = Vector3.right * (AircraftAgents.IndexOf(agent) - AircraftAgents.Count / 2f)
                                     * UnityEngine.Random.Range(5f, 10f);

            //Set the aircraft position and rotation
            agent.transform.position = basePosition + orientation * positionOffset;
            agent.transform.rotation = orientation;
        }
        /// <summary>
        /// Resets the position of an agent using it's current current NextCheckPointIndex
        /// unless randomize is true, then will pick a new random checkpoint
        /// </summary>
        /// <param name="agent">The agent to reset</param>
        /// <param name="randomize">If true, will choose a NextCheckPointIndex before reset</param>
        public void ResetAgentPosition(AircraftAgent agent, bool randomize = false)
        {
            if (randomize)
            {
                // Pick a new NextCheckPointIndex at random
                agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
            }

            // set start position to the previous checkpoint
            int previousCheckPointIndex = agent.NextCheckpointIndex - 1;

            if (previousCheckPointIndex == -1)
            {
                previousCheckPointIndex = Checkpoints.Count - 1;
            }

            float startPosition = racePath.FromPathNativeUnits(previousCheckPointIndex, CinemachinePathBase.PositionUnits.PathUnits);

            // Convert the position on the race path to a position in 3d space
            Vector3 basePosition = racePath.EvaluatePosition(startPosition);

            // Get the orientation at that position on the race path
            Quaternion orientation = racePath.EvaluateOrientation(startPosition);

            // Calculate horizontal offset so that agents are spread out
            Vector3 positionOffset = Vector3.right * (AircraftAgents.IndexOf(agent) - AircraftAgents.Count / 2f)
                                     * UnityEngine.Random.Range(8f, 10f);

            // set the aircraft position and rotation
            agent.transform.position = basePosition + orientation * positionOffset;
            agent.transform.rotation = orientation;
        }
        public void ResetAgentPosition(AircraftAgent agent, bool randomize = false)
        {
            if (randomize)
            {
                agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
            }


            int previousCheckpointIndex = agent.NextCheckpointIndex - 1;

            if (previousCheckpointIndex == -1)
            {
                previousCheckpointIndex = 0;
            }

            float startPosition = racePath.FromPathNativeUnits(previousCheckpointIndex, CinemachinePathBase.PositionUnits.PathUnits);


            Vector3 basePosition = racePath.EvaluatePosition(startPosition);


            Quaternion orientation = racePath.EvaluateOrientation(startPosition);


            Vector3 positionOffset = Vector3.right * (AircraftAgents.IndexOf(agent) - AircraftAgents.Count / 2f)
                                     * UnityEngine.Random.Range(9f, 10f);


            agent.transform.position = basePosition + orientation * positionOffset;
            agent.transform.rotation = orientation;
        }