// Update is called once per frame void Update() { current_turning_direction = 0; if (should_turn_left()) { turn_left(); } if (should_turn_right()) { turn_right(); } if (should_move_forward()) { move_forward(); } if (should_move_backward()) { move_backward(); } if (nitro_is == boost_state.charging) { Nitro += nitro_replenish_rate * Time.deltaTime; } boostBar.SetBoost((int)_nitro); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.Space) && boostAmount >= boostDecrease) { boostAmount -= boostDecrease; boostBar.SetBoost(boostAmount); } if (boostAmount > boostAmountMax) { boostAmount = boostAmountMax; } if ((Input.GetKeyDown(KeyCode.Space)) && (boostAmount >= boostDecrease)) { accelerate.ChangePitchUp(); } if ((Input.GetKeyUp(KeyCode.Space)) || boostAmount <= boostDecrease) { accelerate.ChangePitchDown(); } }
void FixedUpdate() { Transform cam = Camera.main.transform; isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); bool boostUsed = false; transform.rotation = Quaternion.Euler(0f, cam.eulerAngles.y, 0f); fullRotAnchor.transform.rotation = cam.rotation; Vector3 moveDirection = new Vector3(horizontal, 0f, vertical).normalized; if (moveDirection.magnitude >= 0.001f) { float moveAngle = Mathf.Atan2(moveDirection.x, moveDirection.z) * Mathf.Rad2Deg + cam.eulerAngles.y; moveDirection = (Quaternion.Euler(0f, moveAngle, 0f) * Vector3.forward).normalized; if (isBoosting) { moveDirection *= boostForce; boost -= Time.deltaTime; boostUsed = true; boostEffects.SetActive(true); boostEffects.transform.position = playerRB.position - 0.5f * moveDirection.normalized; boostEffects.transform.LookAt(playerRB.transform); } else { moveDirection *= moveForce; } } playerRB.AddForce(moveDirection); //Vector3 hVel = new Vector3(playerRB.velocity.x, 0f, playerRB.velocity.z); Vector3 hVel = playerRB.velocity; hVel.y = 0; playerRB.AddForce(-hVelDragCoef * hVel); if (isJumping) { playerRB.AddForce(0f, jumpForce, 0f); boost -= Time.deltaTime; boostUsed = true; } if (isDiving) { playerRB.AddForce(0f, -diveForce, 0f); boost -= Time.deltaTime; boostUsed = true; } if (!boostUsed) { if (isGrounded) { boost += Time.deltaTime * groundRechargeRate; } else { boost += Time.deltaTime * rechargeRate; } boost = Mathf.Min(boost, maxBoost); } if (boost <= 0) { OnBoostCancel(); OnJumpCancel(); OnDiveCancel(); } boostBar.SetBoost(boost); }