private void StartWoodCutting() { currentLine.DetermineCutDirection(Blade.transform.position); //previousBoardPosition = manager.GetCurrentBoardPosition(); CurrentState = CutState.Cutting; manager.SetUpBoardForCutting(true); }
void OnDisable() { if (currentLine != null) { currentLine.DisplayLine(false, true); currentLine = null; } CurrentState = CutState.ReadyToCut; SawBlade.ResetEdgePosition(); }
public void SetStyle(CutState style, bool enable = true) { if (enable) { state |= style; } else { state &= (~style); } }
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; }
/// <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; }
void Update() { #region CuttingCode if (manager.StillCutting) { currentPiecePosition = manager.GetCurrentBoardPosition(); totalTimePassed += Time.deltaTime; UpdateFeedRateData(); if (CurrentState == CutState.ReadyToCut) { SwitchDado(); if (SawBlade.CuttingWoodBoard && SawBlade.SawBladeActive) { StartWoodCutting(); CurrentState = CutState.Cutting; manager.RestrictCurrentBoardMovement(false, true); } } else if (CurrentState == CutState.Cutting && SawBlade.SawBladeActive) { if (cuttingOutDado) { if (SawBlade.NoInteractionWithBoard && !PieceWithinBlade()) { CurrentState = CutState.EndOfCut; } else { if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; FeedRateTracker.UpdateScoreWithRate(playerFeedRate); } if (FeedRateTracker.RateTooSlow || FeedRateTracker.RateTooFast) { totalTimeStalling += Time.deltaTime; FeedRateTracker.ReduceScoreDirectly(0.1f); if (totalTimeStalling >= MaxStallTime && FeedRateTracker.RateTooSlow) { manager.StopGameDueToLowScore("You were cutting too slow, now the wood is burnt."); } else if (totalTimeStalling >= 1.0f && FeedRateTracker.RateTooFast) { manager.StopGameDueToLowScore("You were cutting too fast and caused the saw to bind."); } } } } else { if (SawBlade.NoInteractionWithBoard && !PieceWithinBlade()) { timeNotCuttingLine = 0.0f; CurrentState = CutState.ReadyToCut; SawBlade.ResetEdgePosition(); currentDado = null; manager.RestrictCurrentBoardMovement(false, false); } else { timeNotCuttingLine += Time.deltaTime; if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; FeedRateTracker.ReduceScoreDirectly(0.6f); } if (timeNotCuttingLine >= MaxStallTime) { manager.StopGameDueToLowScore("You were not cutting into the marked dado cut, and now the board is ruined."); } } } } else if (CurrentState == CutState.EndOfCut) { if (!SawBlade.CuttingWoodBoard && SawBlade.NoInteractionWithBoard && !PieceWithinBlade()) { currentDado.ScaleDown(); if (!currentDado.AnyCutsLeft()) { manager.DisplayScore(FeedRateTracker); FeedRateTracker.ResetFeedRate(); } manager.SplitMaterial(currentDado); cuttingOutDado = false; currentDado = null; SawBlade.ResetEdgePosition(); CurrentState = CutState.ReadyToCut; manager.RestrictCurrentBoardMovement(false, false); } } #endregion previousPiecePosition = currentPiecePosition; if (FeedRateTracker.GetLineScore() <= 0.0f) { manager.StopGameDueToLowScore("This cut is too messed up to keep going."); } if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; } } }
void Start() { CurrentState = CutState.ReadyToCut; }
void Start() { currentLine = null; cuttingAlongLine = false; CurrentState = CutState.ReadyToCut; }
void Update() { #region CuttingCode if (manager.StillCutting) { currentBladePosition = SawBlade.EdgePosition(); totalTimePassed += Time.deltaTime; UpdateFeedRateDate(); if (CurrentState == CutState.ReadyToCut) { SwitchLine(); if (SawBlade.CuttingWoodBoard && SawBlade.SawBladeActive) { Vector3 origin = SawBlade.EdgePosition() + new Vector3(0.0f, 0.5f, 0.0f); Ray ray = new Ray(origin, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover")) { Vector3 bladeEdgePosition = new Vector3(currentLine.GetCurrentCheckpointPosition().x, hit.point.y, hit.point.z); StartWoodCutting(bladeEdgePosition); } } } else if (CurrentState == CutState.Cutting && SawBlade.SawBladeActive) { if (cuttingAlongLine) { currentLine.UpdateLine(SawBlade.EdgePosition()); if (currentLine.LineIsCut()) { CurrentState = CutState.EndingCut; } else { if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; totalTimeStalling = 0.0f; FeedRateTracker.UpdateScoreWithRate(playerFeedRate); } if (FeedRateTracker.RateTooSlow || FeedRateTracker.RateTooFast) { totalTimeStalling += Time.deltaTime; FeedRateTracker.ReduceScoreDirectly(0.1f); if (totalTimeStalling >= MaxStallTime && FeedRateTracker.RateTooSlow) { manager.StopGameDueToLowScore("You were cutting too slow, now the wood is burnt."); } else if (totalTimeStalling >= 1.0f && FeedRateTracker.RateTooFast) { manager.StopGameDueToLowScore("You were cutting too fast and caused the saw to bind."); } } } } else { if (SawBlade.NoInteractionWithBoard) { timeNotCuttingLine = 0.0f; CurrentState = CutState.ReadyToCut; SawBlade.ResetEdgePosition(); currentLine = null; manager.RestrictCurrentBoardMovement(false, false); } else { timeNotCuttingLine += Time.deltaTime; if (totalTimePassed >= timeUpdateFrequency) { totalTimePassed = 0.0f; FeedRateTracker.ReduceScoreDirectly(0.8f); } if (timeNotCuttingLine >= MaxStallTime) { manager.StopGameDueToLowScore("You were not cutting along the line, and now the board is ruined."); } } } } else if (CurrentState == CutState.EndingCut) { if (!SawBlade.CuttingWoodBoard && SawBlade.NoInteractionWithBoard) { manager.DisplayScore(FeedRateTracker); manager.SplitMaterial(currentLine); cuttingAlongLine = false; currentLine = null; SawBlade.ResetEdgePosition(); CurrentState = CutState.ReadyToCut; FeedRateTracker.ResetFeedRate(); } } } previousBladePosition = currentBladePosition; if (FeedRateTracker.GetLineScore() <= 0.0f) { manager.StopGameDueToLowScore("This cut is too messed up to keep going."); } #endregion }
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 }
void Start() { currentLine = null; //timeStalling = 0.0f; CurrentState = CutState.ReadyToCut; }