コード例 #1
0
        /// <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;
        }
コード例 #2
0
ファイル: CarArea.cs プロジェクト: Rohit-v-raj/Speed
    public void ResetAgentPosition(CarAgent agent, bool randomize = false)
    {
        if (randomize)
        {
            agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
        }


        int previousCheckpointIndex = agent.NextCheckpointIndex - 1;

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

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


        Vector3 basePosition = racePath.EvaluatePosition(startPosition);


        Quaternion orientation = racePath.EvaluateOrientation(startPosition);


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


        agent.transform.position = basePosition + orientation * positionOffset;
        agent.transform.rotation = orientation;
    }
コード例 #3
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;
        }
コード例 #4
0
    public void ResetCarAgent(CarAgent agent, Vector3 offset)
    {
        int prevCheckpointIndex = agent.NextCheckpointIndex - 1;

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

        float Startposition = racePath.FromPathNativeUnits(prevCheckpointIndex, CinemachinePathBase.PositionUnits.PathUnits);

        Vector3    basePosition   = racePath.EvaluatePosition(Startposition);
        Quaternion orientation    = racePath.EvaluateOrientation(Startposition);
        Vector3    offsetPosition = Vector3.right * (carAgents.IndexOf(agent) - carAgents.Count / 2f);

        //Debug.Log(offsetPosition);
        agent.transform.position = basePosition + orientation * offset;//offsetPosition;
        agent.transform.rotation = orientation;
    }