示例#1
0
        void startChangingLanes(Lane _nextLane)
        {
            if (isChangingLanes)
            {
                return;
            }
            isChangingLanes = true;

            trajectory.generateChangeWaypoint(this.transform, length, _nextLane);

            updateCurrentLane(preferedLane);
        }
示例#2
0
        public void setCurrentLane(Lane lane)
        {
            currentLane = lane;
            if (lane.getRoad() != currentLane.getRoad())
            {
                currentRoad = lane.getRoad();
            }

            Road nextRoad = getNextRoad();

            if (nextRoad != null)
            {
                willNearTurn = Util.getRltDirection(currentRoad.direction, nextRoad.direction) == RltDirection.Right;
                willFarTurn  = Util.getRltDirection(currentRoad.direction, nextRoad.direction) == RltDirection.Left;
            }
        }
示例#3
0
 void changeLane(Lane _nextLane)
 {
     if (isChangingLanes)
     {
         return;
     }
     if (_nextLane == null)
     {
         return;
     }
     if (_nextLane == trajectory.getCurrentLane())
     {
         return;
     }
     //if(nextPosition = @current.position + 3 * @car.length
     //throw Error 'too late to change lane' unless nextPosition < @lane.length)
     startChangingLanes(_nextLane);
 }
 public Lane getRightAdjacentLane(Lane lane)
 {
     if (lane.getRoad() != this)
     {
         return(null);
     }
     else
     {
         Lane tempLane = getRightmostLane();
         for (int i = 0; i < numOfLanes; i++)
         {
             if (lane == lanes[i] && i < numOfLanes - 1)
             {
                 tempLane = lanes[i + 1];
             }
         }
         return(tempLane);
     }
 }
示例#5
0
        void prepareChangingLane(bool shouldTurn)
        {
            RltDirection turnDir = trajectory.getNextRltDirection();

            //Debug.Log(isChangingLanes.ToString() + turnDir.ToString());

            if (!isChangingLanes && turnDir != RltDirection.NA)
            {
                switch (turnDir)
                {
                case RltDirection.Left:
                    if (shouldTurn)
                    {
                        preferedLane = trajectory.getCurrentRoad().getLeftmostLane();
                    }
                    else if (trajectory.currentLane != trajectory.getCurrentRoad().getLeftmostLane())
                    {
                        preferedLane = trajectory.getLeftAdjacentLane();
                    }
                    break;

                case RltDirection.Right:
                    if (shouldTurn)
                    {
                        preferedLane = trajectory.getCurrentRoad().getRightmostLane();
                    }
                    else if (trajectory.currentLane != trajectory.getCurrentRoad().getRightmostLane())
                    {
                        preferedLane = trajectory.getRightAdjacentLane();
                    }
                    break;

                default:
                    preferedLane = trajectory.getCurrentLane();
                    break;
                }
                if (preferedLane != trajectory.getCurrentLane())
                {
                    changeLane(preferedLane);
                }
            }
        }
示例#6
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (transform.position.y < 0 || transform.position.y > 10)
            {
                alive = false;
            }
            if (alive)
            {
                if (!shouldStop() && isAtTheEnd())
                {
                    //Debug.Log("isAtTheEnd");
                    trajectory.updateCurrentLaneAtEnd();
                    if (trajectory.isFarTurning || trajectory.isNearTurning)
                    {
                        isTurning    = true;
                        preferedLane = null;
                    }
                }

                if (isTurning)
                {
                    turn();
                }
                else
                {
                    if (shouldPrepareTurn())
                    {
                        decisionCount = -1;
                    }
                    changeLaneForTurn();
                }
                setAligned();
                setSpeed();
                visualizeCollider();
            }
        }
示例#7
0
 public int getTurnDirection(Lane other)
 {
     return(-1);
     //return road.getTurnDirection(other.road);
 }
示例#8
0
 void updateCurrentLane(Lane lane)
 {
     trajectory.setCurrentLane(lane);
     preferedLane = null;
 }
示例#9
0
 private float getCurPosition(Lane _lane)
 {
     return(Vector3.Distance(transform.position, _lane.toPoint) / _lane.length);
 }
 public LanePosition(Car car, Lane lane, Vector3 position)
 {
 }