Exemple #1
0
        bool pathsCross(CarAI otherCarAI)
        {
            bool cross       = false;
            int  nextNPoints = 6;
            int  prevNPoints = 4;

            List <int> myNextPoints    = new List <int>();
            List <int> otherNextPoints = new List <int>();


            if (targetIndex + nextNPoints < ownPath.Count && targetIndex - prevNPoints >= 0)
            {
                myNextPoints = ownPath.GetRange(targetIndex - prevNPoints, nextNPoints);
            }

            if (otherCarAI.targetIndex + nextNPoints < otherCarAI.ownPath.Count && otherCarAI.targetIndex - prevNPoints >= 0)
            {
                otherNextPoints = otherCarAI.ownPath.GetRange(otherCarAI.targetIndex - prevNPoints, nextNPoints);
            }

            for (int i = 0; i < myNextPoints.Count; i++)
            {
                if (otherNextPoints.Contains(myNextPoints[i]))
                {
                    cross = true;
                }
            }
            return(cross);
        }
Exemple #2
0
        void calculateBearing()
        {
            CarAI otherCarAI = carHit.GetComponent <CarAI>();

            ourDis = ownPath.Count - targetIndex;                                      //-(0.1f*temp);//Vector3.Distance(transform.position,goal_pos);
            float otherDis = otherCarAI.ownPath.Count - otherCarAI.targetIndex;        //-(0.1f*otherCarAI.temp);//Vector3.Distance(carHit.transform.position,otherCarAI.goal_pos);

            if (Aggressiveness < otherCarAI.Aggressiveness && !pathsCross(otherCarAI)) //ourDis>otherDis
            {
                temp++;
                waitTimer = 50;
                Vector3 vel = m_Car.GetComponent <Rigidbody>().velocity;
                if (transform.InverseTransformDirection(vel).z > 0.01)
                {
                    newSpeed  = -1;
                    handBrake = 1;
                }
                else if (transform.InverseTransformDirection(vel).z < -0.01)
                {
                    newSpeed  = 1;
                    handBrake = 1;
                }
                else
                {
                    newSpeed  = 0;
                    handBrake = 1;
                }
                m_Car.Move(0, newSpeed, newSpeed, handBrake);
            }

            else
            {
                followPath();
            }
        }