public void Execute() { float x = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed; if (Mathf.Abs(movingBody.velocity.x) < movementSpeed / 100f && Mathf.Abs(x) > 0f) { movingBody.AddForce(new Vector2(x / 4f, 0f), ForceMode2D.Impulse); } else { if (playerController.grounded) { movingBody.velocity *= 0.9f; } } if (x == 0 && idlingResultsCallback != null) { secondsOfNoInput += Time.deltaTime; if (secondsOfNoInput >= secondsOfNoMovementBeforeIdle) { IdlingResults idlingResults = new IdlingResults(secondsOfNoMovementBeforeIdle); idlingResultsCallback(idlingResults); } } }
private void StopIdling(IdlingResults idlingResults) { //Debug.Log(gameObject.name + " spent " + idlingResults.timeIdled + " seconds idling."); if (CheckForClearPatrollingDirection()) { StartPatrolling(); } else { //Debug.Log("No clear area to partoll, idling again..."); stateMachine.ChangeState(new IdleState(5f, StopIdling)); } }
public void Execute() { if (timeToIdle != 0f) { if (timeSpentIdling < timeToIdle) { timeSpentIdling += Time.deltaTime; } else { var idlingResults = new IdlingResults(timeSpentIdling); idlingResultsCallback(idlingResults); } } }
public void Execute() { float x = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed; movingBody.AddForce(new Vector2(x, 0f)); if (x == 0 && idlingResultsCallback != null) { secondsOfNoInput += Time.deltaTime; if (secondsOfNoInput >= secondsOfNoMovementBeforeIdle) { IdlingResults idlingResults = new IdlingResults(secondsOfNoMovementBeforeIdle); idlingResultsCallback(idlingResults); } } }
public void IdlingLoopRestart(IdlingResults idlingResults) { //Debug.Log("Idle loop restarted after " + idlingResults.timeIdled + "seconds."); stateMachine.ChangeState(new IdleState(10f, IdlingLoopRestart)); }