Beispiel #1
0
    void Update()
    {
        if (_isStopped)
        {
            return;
        }

        transform.position = Vector2.MoveTowards(transform.position, _targetPos, Time.deltaTime * _curSpeed);
        if (!_nextRail.IsCurve)
        {
            if (Vector2.Distance(new Vector2(transform.position.x, transform.position.y), _targetPos) < 0.005f)
            {
                transform.position = _targetPos;
                _curRail           = _nextRail;
                GetNextTarget(_nextRail.GetNextRail().x, _nextRail.GetNextRail().y);
                RotateToTarget();
            }
        }
        else
        {
            if (Vector2.Distance(new Vector2(transform.position.x, transform.position.y), _targetPos) < 0.005f)
            {
                if (!_rotateDone)
                {
                    _rotateDone = true;
                    GetCurvePoints(out Vector2 curvP1, out Vector2 curvP2);
                    _targetPos = new Vector2(_nextRail.x, _nextRail.y) + curvP2;
                    RotateToTarget();
                }
                else
                {
                    _curRail = _nextRail;
                    GetNextTarget(_nextRail.GetNextRail().x, _nextRail.GetNextRail().y);
                    RotateToTarget();
                }
            }
        }
    }
Beispiel #2
0
        public void SpawnTrain(WorldTileRail startRail)
        {
            GameObject copy = Instantiate(TrainPrefab);

            copy.GetComponent <TrainMovment>().StartTrain(startRail);
        }
Beispiel #3
0
    private void GetCurvePoints(out Vector2 firstPoint, out Vector2 secondPoint)
    {
        WorldTileRail nextNextRail = _nextRail.GetNextRail();
        bool?         isAbove      = _nextRail.CheckIfPointIsAboveDir();

        firstPoint  = Vector2.zero;
        secondPoint = Vector2.zero;
        //Debug.Log($"{nextRail.CompassDirection} | {isAbove.Value}");
        switch (_nextRail.CompassDirection)
        {
        case CompassDirection.NE:
            if (isAbove.HasValue && isAbove.Value)
            {
                firstPoint  = new Vector2(0.5f, 0f);
                secondPoint = new Vector2(1f, 0.5f);
            }
            else
            {
                firstPoint  = new Vector2(0f, 0.5f);
                secondPoint = new Vector2(0.5f, 1f);
            }
            break;

        case CompassDirection.SW:
            if (isAbove.HasValue && isAbove.Value)
            {
                firstPoint  = new Vector2(1f, 0.5f);
                secondPoint = new Vector2(0.5f, 0f);
            }
            else
            {
                firstPoint  = new Vector2(0.5f, 1f);
                secondPoint = new Vector2(0, 0.5f);
            }
            break;

        case CompassDirection.SE:
            if (isAbove.HasValue && isAbove.Value)
            {
                firstPoint  = new Vector2(0f, 0.5f);
                secondPoint = new Vector2(0.5f, 0);
            }
            else
            {
                firstPoint  = new Vector2(0.5f, 1f);
                secondPoint = new Vector2(1f, 0.5f);
            }

            break;

        case CompassDirection.NW:
            if (isAbove.HasValue && isAbove.Value)
            {
                firstPoint  = new Vector2(0.5f, 0);
                secondPoint = new Vector2(0f, 0.5f);
            }
            else
            {
                firstPoint  = new Vector2(1f, 0.5f);
                secondPoint = new Vector2(0.5f, 1f);
            }

            break;
        }
    }