Ejemplo n.º 1
0
    public bool DoorsClosed()
    {
        Vector3 _DOOR_POS = door_LEFT.localPosition;
        bool    arrived   = Approach.Apply(ref _DOOR_POS.x, ref door_SPEED, left_CLOSED_X, DOOR_ACCELERATION,
                                           DOOR_ARRIVAL_THRESHOLD, DOOR_FRICTION);

        door_LEFT.localPosition  = _DOOR_POS;
        door_RIGHT.localPosition = new Vector3(-_DOOR_POS.x, _DOOR_POS.y, _DOOR_POS.z);
        return(arrived);
    }
Ejemplo n.º 2
0
    public static bool Apply(ref Transform _transform, ref Vector3 _speed, Vector3 _destination, float _acceleration,
                             float _arrivalThreshold, float _friction)
    {
        Vector3 _POS = _transform.position;

        bool arrivedX = Approach.Apply(ref _POS.x, ref _speed.x, _destination.x, _acceleration, _arrivalThreshold, _friction);
        bool arrivedY = Approach.Apply(ref _POS.y, ref _speed.y, _destination.y, _acceleration, _arrivalThreshold, _friction);
        bool arrivedZ = Approach.Apply(ref _POS.z, ref _speed.z, _destination.z, _acceleration, _arrivalThreshold, _friction);

        _transform.position = _POS;

        return(arrivedX && arrivedY && arrivedZ);
    }
Ejemplo n.º 3
0
    public void UpdateCommuter()
    {
        switch (currentTask.state)
        {
        case CommuterState.WALK:
            if (Approach.Apply(ref t, ref speed, currentTask.destinations[currentTask.destinationIndex],
                               acceleration,
                               ARRIVAL_THRESHOLD, FRICTION))
            {
                currentTask.destinationIndex++;
                if (currentTask.destinationIndex > currentTask.destinations.Length - 1)
                {
                    currentPlatform = currentTask.endPlatform;
                    NextTask();
                }
            }

            break;

        case CommuterState.QUEUE:

            float   offset      = currentQueue.Count * QUEUE_PERSONAL_SPACE;
            Vector3 queueOffset = currentPlatform.transform.forward * offset;
            Vector3 _DEST       = currentPlatform.queuePoints[carriageQueueIndex].transform.position + queueOffset;
            if (!currentQueue.Contains(this))
            {
                if (Approach.Apply(ref t, ref speed, _DEST, acceleration, ARRIVAL_THRESHOLD, FRICTION))
                {
                    myQueueIndex = currentQueue.Count;
                    currentPlatform.platformQueues[carriageQueueIndex].Enqueue(this);
                }
                else
                {
                    if (Timer.TimerReachedZero(ref stateDelay))
                    {
                        carriageQueueIndex = currentPlatform.Get_ShortestQueue();
                        currentQueue       = currentPlatform.platformQueues[carriageQueueIndex];
                        stateDelay         = QUEUE_DECISION_RATE;
                    }
                }
            }
            ;
            break;

        case CommuterState.GET_ON_TRAIN:
            // brief wait before boarding
            if (Timer.TimerReachedZero(ref stateDelay))
            {
                // walk to each destination in turn (door, seat)
                if (Approach.Apply(ref t, ref speed, currentTask.destinations[currentTask.destinationIndex],
                                   acceleration,
                                   ARRIVAL_THRESHOLD, FRICTION))
                {
                    currentTask.destinationIndex++;
                    // if this is the last destination - go to next task (WAIT_FOR_STOP)
                    if (currentTask.destinationIndex > currentTask.destinations.Length - 1)
                    {
                        currentTrain.Commuter_EMBARKED(this, carriageQueueIndex);
                        NextTask();
                    }
                }
            }

            break;

        case CommuterState.WAIT_FOR_STOP:
            break;

        case CommuterState.GET_OFF_TRAIN:
            // walk to each destination in turn (door, platform)
            if (Approach.Apply(ref t, ref speed, currentTask.destinations[currentTask.destinationIndex],
                               acceleration,
                               ARRIVAL_THRESHOLD, FRICTION))
            {
                currentTask.destinationIndex++;
                // if this is the last destination - go to next task
                if (currentTask.destinationIndex > currentTask.destinations.Length - 1)
                {
                    currentTrain.Commuter_DISEMBARKED(this, carriageQueueIndex);
                    NextTask();
                }
            }

            break;
        }
    }