Example #1
0
    public void SetupRunner(BuiltPathPiece startingBPP, Transform startingLocation)
    {
        currentLane          = RunningLane.Mid;
        currentMoveDirection = MoveDirection.North;

        transform.position = startingLocation.position;
        transform.rotation = startingLocation.rotation;

        currentBPP = startingBPP;
    }
Example #2
0
    //Code to turn the runner on a piece to face a new direction
    //[TODO] Really long. Clean it up in the future
    void TurnRunner(float inputDir)
    {
        bool isLeftTurn  = false;
        bool isRightTurn = false;

        lastMidPos = currentMidLanePos;

        if (inputDir > 0f)
        {
            isRightTurn       = true;
            lastTurnIsRight   = true;
            currentMidLanePos = nextRightMidPos;
        }
        else
        {
            isLeftTurn        = true;
            lastTurnIsLeft    = true;
            currentMidLanePos = nextLeftMidPos;
        }

        transform.eulerAngles += new Vector3(0f, inputDir * 90f, 0f);

        if ((int)currentMoveDirection + inputDir < 1)
        {
            currentMoveDirection = MoveDirection.West;
        }
        else if ((int)currentMoveDirection + inputDir > 4)
        {
            currentMoveDirection = MoveDirection.North;
        }
        else
        {
            currentMoveDirection = (MoveDirection)((int)currentMoveDirection + inputDir);
        }

        canTurn = false;

        Vector3 currentPos = transform.position;

        Debug.Log("Pre turn pos " + currentPos);

        bool turningOntoPiece = false;

        if (isRightTurn && nextRightMidPos != Vector3.zero)
        {
            turningOntoPiece = true;
            Debug.Log("Right to " + nextRightMidPos);
        }
        else if (isLeftTurn && nextLeftMidPos != Vector3.zero)
        {
            turningOntoPiece = true;
            Debug.Log("Left to " + nextLeftMidPos);
        }

        float distToNextMidLane   = 0f;
        float distToNextLeftLane  = 0f;
        float distToNextRightLane = 0f;

        if (turningOntoPiece)
        {
            //Teleport for now
            switch (currentMoveDirection)
            {
            case MoveDirection.North:
                if (isRightTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.x - (nextLeftMidPos.x - 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.x - (nextLeftMidPos.x));
                    distToNextRightLane = Mathf.Abs(currentPos.x - (nextLeftMidPos.x + 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.x = nextRightMidPos.x + 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.x = nextRightMidPos.x - 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.x = nextRightMidPos.x;
                        currentLane  = RunningLane.Mid;
                    }
                }
                else if (isLeftTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.x - (nextLeftMidPos.x - 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.x - (nextLeftMidPos.x));
                    distToNextRightLane = Mathf.Abs(currentPos.x - (nextLeftMidPos.x + 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.x = nextLeftMidPos.x + 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.x = nextLeftMidPos.x - 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.x = nextRightMidPos.x;
                        currentLane  = RunningLane.Mid;
                    }
                }
                break;

            case MoveDirection.East:
                if (isRightTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.z - (nextLeftMidPos.z + 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.z - (nextLeftMidPos.z));
                    distToNextRightLane = Mathf.Abs(currentPos.z - (nextLeftMidPos.z - 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.z = nextRightMidPos.z - 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.z = nextRightMidPos.z + 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.z = nextRightMidPos.z;
                        currentLane  = RunningLane.Mid;
                    }
                }
                else if (isLeftTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.z - (nextLeftMidPos.z + 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.z - (nextLeftMidPos.z));
                    distToNextRightLane = Mathf.Abs(currentPos.z - (nextLeftMidPos.z - 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.z = nextLeftMidPos.z - 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.z = nextLeftMidPos.z + 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.z = nextRightMidPos.z;
                        currentLane  = RunningLane.Mid;
                    }
                }
                break;

            case MoveDirection.South:
                if (isRightTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.x - (nextLeftMidPos.x + 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.x - (nextLeftMidPos.x));
                    distToNextRightLane = Mathf.Abs(currentPos.x - (nextLeftMidPos.x - 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.x = nextRightMidPos.x - 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.x = nextRightMidPos.x + 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.x = nextRightMidPos.x;
                        currentLane  = RunningLane.Mid;
                    }
                }
                else if (isLeftTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.x - (nextLeftMidPos.x + 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.x - (nextLeftMidPos.x));
                    distToNextRightLane = Mathf.Abs(currentPos.x - (nextLeftMidPos.x - 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.x = nextLeftMidPos.x - 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.x = nextLeftMidPos.x + 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.x = nextRightMidPos.x;
                        currentLane  = RunningLane.Mid;
                    }
                }
                break;

            case MoveDirection.West:
                if (isRightTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.z - (nextRightMidPos.z - 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.z - (nextRightMidPos.z));
                    distToNextRightLane = Mathf.Abs(currentPos.z - (nextRightMidPos.z + 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.z = nextRightMidPos.z + 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.z = nextRightMidPos.z - 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.z = nextRightMidPos.z;
                        currentLane  = RunningLane.Mid;
                    }
                }
                else if (isLeftTurn)
                {
                    distToNextLeftLane  = Mathf.Abs(currentPos.z - (nextLeftMidPos.z - 2f));
                    distToNextMidLane   = Mathf.Abs(currentPos.z - (nextLeftMidPos.z));
                    distToNextRightLane = Mathf.Abs(currentPos.z - (nextLeftMidPos.z + 2f));
                    //Debug.Log("Left " + distToNextLeftLane + " mid " + distToNextMidLane + " right " + distToNextRightLane);

                    if (distToNextRightLane <= distToNextMidLane &&
                        distToNextRightLane <= distToNextLeftLane)
                    {
                        currentPos.z = nextLeftMidPos.z + 2f;
                        currentLane  = RunningLane.Right;
                    }
                    else if (distToNextLeftLane <= distToNextMidLane &&
                             distToNextLeftLane <= distToNextRightLane)
                    {
                        currentPos.z = nextLeftMidPos.z - 2f;
                        currentLane  = RunningLane.Left;
                    }
                    else
                    {
                        currentPos.z = nextRightMidPos.z;
                        currentLane  = RunningLane.Mid;
                    }
                }
                break;
            }
        }
        else
        {
            Debug.Log("Don't turn?");
        }
        //Debug.Log("current pos " + currentPos);
        transform.position = currentPos;

        nextLeftMidPos  = Vector3.zero;
        nextRightMidPos = Vector3.zero;
    }
Example #3
0
    public void DoRight()
    {
        CheckWallRunning(1);

        if (canTurn)
        {
            TurnRunner(1f);
        }
        else
        {
            //Clear left Enemy as you move away

            RunningLane lastLane = currentLane;

            switch (currentLane)
            {
            case RunningLane.Left:
                currentLane  = RunningLane.Mid;
                doLaneChange = true;
                break;

            case RunningLane.Mid:
                currentLane  = RunningLane.Right;
                doLaneChange = true;
                break;

            case RunningLane.Right:
                doLaneChange = false;
                break;
            }

            if (doLaneChange)
            {
                pAniController.RightLaneChangeAnimation();
                switch (currentMoveDirection)
                {
                case MoveDirection.North:
                    switch (lastLane)
                    {
                    case RunningLane.Mid:
                        startX = currentMidLanePos.x;
                        break;

                    case RunningLane.Left:
                        startX = currentMidLanePos.x - laneChangeDistance;
                        break;
                    }
                    goalX = startX + laneChangeDistance;
                    break;

                case MoveDirection.South:
                    switch (lastLane)
                    {
                    case RunningLane.Mid:
                        startX = currentMidLanePos.x;
                        break;

                    case RunningLane.Left:
                        startX = currentMidLanePos.x + laneChangeDistance;
                        break;
                    }
                    goalX = startX - laneChangeDistance;
                    break;

                case MoveDirection.West:
                    switch (lastLane)
                    {
                    case RunningLane.Mid:
                        startZ = currentMidLanePos.z;
                        break;

                    case RunningLane.Left:
                        startZ = currentMidLanePos.z - laneChangeDistance;
                        break;
                    }
                    goalZ = startZ + laneChangeDistance;
                    break;

                case MoveDirection.East:
                    switch (lastLane)
                    {
                    case RunningLane.Mid:
                        startZ = currentMidLanePos.z;
                        break;

                    case RunningLane.Left:
                        startZ = currentMidLanePos.z + laneChangeDistance;
                        break;
                    }
                    goalZ = startZ - laneChangeDistance;
                    break;
                }
            }
        }
    }