Exemplo n.º 1
0
    public bool MarkIsNearLine(CutLine line, Vector3 markPosition)
    {
        bool closeToLine = false;

        if (line.CutType == CutLineType.TableSawCut)
        {
            float distanceToLine = line.CalculateDistance(markPosition);
            closeToLine = (distanceToLine < OffsetFromLine);
        }
        else if (line.CutType == CutLineType.ChopSawCut)
        {
            Vector3 linePosition           = line.Checkpoints[0].GetPosition();
            Vector3 adjustedMarkedPosition = new Vector3(markPosition.x, linePosition.y, markPosition.z);
            Vector3 toAdjustedMark         = adjustedMarkedPosition - linePosition;
            Vector3 rightOfLine            = (linePosition + line.Checkpoints[0].transform.forward) - linePosition;
            float   projectionOntoLine     = Vector3.Dot(toAdjustedMark, rightOfLine);
            closeToLine = (Mathf.Abs(projectionOntoLine) < OffsetFromLine);
        }
        return(closeToLine);
    }
    private void StartWoodCutting(Vector3 cutStartPoint)
    {
        SawBlade.SetEdgePosition(cutStartPoint);
        currentLine.DetermineCutDirection(SawBlade.EdgePosition());

        float distanceFromBlade = currentLine.CalculateDistance(SawBlade.EdgePosition());

        cuttingAlongLine = (distanceFromBlade <= ValidCutOffset);
        if (cuttingAlongLine && distanceFromBlade >= 0.003f)
        {
            FeedRateTracker.ReduceScoreDirectly(0.5f);
        }
        else if (!cuttingAlongLine)
        {
            FeedRateTracker.ReduceScoreDirectly(1.0f);
        }

        manager.RestrictCurrentBoardMovement(true, true);
        previousBladePosition = SawBlade.EdgePosition();
        CurrentState          = CutState.Cutting;
        totalTimePassed       = 0.0f;
    }
Exemplo n.º 3
0
    /// <summary>
    /// When the blade hits the wood material, set up the blade edge to better track how close the blade is to the line.
    /// </summary>
    /// <param name="cutStartPoint">The point at which the blade hit the wood material</param>
    private void StartWoodCutting(Vector3 cutStartPoint)
    {
        SawBlade.SetEdgePosition(cutStartPoint);
        currentLine.DetermineCutDirection(SawBlade.EdgePosition());

        float distanceFromBlade = currentLine.CalculateDistance(SawBlade.EdgePosition());

        cuttingAlongLine = (distanceFromBlade <= ValidCutOffset);
        //If the blade is already to far from the line, change the score in the Feed Rate
        if (cuttingAlongLine && distanceFromBlade >= 0.003f)
        {
            FeedRateTracker.ReduceScoreDirectly(0.5f);
        }
        else if (!cuttingAlongLine)
        {
            FeedRateTracker.ReduceScoreDirectly(1.0f);
        }
        //Restrict the movement of the board to just the z direction
        manager.RestrictCurrentBoardMovement(false, true);
        previousPiecePosition = manager.GetCurrentBoardPosition();
        CurrentState          = CutState.Cutting;
        totalTimePassed       = 0.0f;
    }
Exemplo n.º 4
0
    void Update()
    {
        #region CuttingCode
        if (manager.StillCutting)
        {
            totalTimePassed += Time.deltaTime;
            if (CurrentState == CutState.ReadyToCut)
            {
                SwitchLine();

                if (Blade.CuttingWoodBoard && Blade.SawActive)
                {
                    Vector3    origin = Blade.transform.position + new Vector3(0.0f, 0.1f, 0.0f);
                    Ray        ray    = new Ray(origin, Vector3.down);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover" || hit.collider.tag == "Dado"))
                    {
                        hit.collider.gameObject.transform.parent.GetComponent <BandSawPieceController>().RotationPoint = hit.point;
                        StartWoodCutting();
                    }
                }
            }
            else if (CurrentState == CutState.Cutting && Blade.SawActive)
            {
                float distanceFromBlade = currentLine.CalculateDistance(Blade.transform.position);
                bool  cuttingAlongLine  = (distanceFromBlade <= ValidCutOffset);
                if (cuttingAlongLine)
                {
                    currentLine.UpdateLine(Blade.transform.position, ValidCutOffset);
                    if (currentLine.LineIsCut())
                    {
                        CurrentState = CutState.EndOfCut;
                    }
                    if (totalTimePassed >= timeUpdateFrequency)
                    {
                        totalTimePassed = 0.0f;
                        if (distanceFromBlade <= ValidCutOffset && distanceFromBlade >= 0.015f)
                        {
                            lineScore -= 0.2f;
                        }
                        else if (distanceFromBlade <= 0.015f && distanceFromBlade >= 0.01f)
                        {
                            lineScore -= 0.1f;
                        }
                    }
                }
                else
                {
                    if (totalTimePassed >= timeUpdateFrequency)
                    {
                        totalTimePassed = 0.0f;
                        lineScore      -= 0.5f;
                    }
                    totalTimeNotCuttingLine += Time.deltaTime;
                    if (totalTimeNotCuttingLine >= MaxTimeAwayFromLine)
                    {
                        manager.StopGameDueToLowScore("You've messed up the wood too much.");
                    }
                    else if (Blade.NoInteractionWithBoard)
                    {
                        CurrentState = CutState.ReadyToCut;
                        Blade.ResetEdgePosition();
                        currentLine.Reset();
                        currentLine = null;
                        manager.SetUpBoardForCutting(false);
                    }
                }
            }
            else if (CurrentState == CutState.EndOfCut)
            {
                if (!Blade.CuttingWoodBoard && Blade.NoInteractionWithBoard)
                {
                    manager.DisplayScore(lineScore);
                    lineScore = 100.0f;
                    manager.SetUpBoardForCutting(false);
                    manager.SplitMaterial(currentLine);
                    currentLine = null;
                    Blade.ResetEdgePosition();
                    CurrentState = CutState.ReadyToCut;
                }
            }

            if (lineScore <= 0.0f)
            {
                manager.StopGameDueToLowScore("This cut is too messed up to keep going.");
            }

            if (totalTimePassed >= timeUpdateFrequency)
            {
                totalTimePassed = 0.0f;
            }
        }
        #endregion
    }