private void FixedUpdate() { if (_isReady && _canMove && _inputActive) { _playerData.TimeAccelerated += Time.deltaTime; float distance = _playerData.TimeAccelerated * _playerConfig.Speed; Vector3 dir = _intervalStart.Finish.position - _intervalStart.Start.position; Vector3 velocity = dir.normalized * _playerConfig.Speed * Time.deltaTime; transform.Translate(velocity); _model.rotation = Quaternion.Lerp(_model.rotation, Quaternion.LookRotation(dir), _playerData.TimeAccelerated); float percent = InverseLerp(_intervalStart.Start.position, _intervalStart.Finish.position, _intervalStart.Start.position + (dir.normalized * distance)); if (percent >= 1 && _trackController.IsLastInterval()) { // win Debug.Log("WIN"); _levelController.ShowWinPopup(); _canMove = false; } else if (percent >= 1) { // Player passed the interval get next interval _intervalStart = _trackController.NextInterval(); _playerData.TimeAccelerated = 0; } } }
public void Respawn() { _canMove = true; _rb.isKinematic = true; _playerData.TimeAccelerated = 0; _trackController.ResetToCheckpoint(); _intervalStart = _trackController.GetCurrentTrackPoint(); transform.position = _intervalStart.Start.position; transform.rotation = Quaternion.identity; }
public void Init(LevelController levelControler, PlayerConfig playerConfig, TrackController currentTrack) { _levelController = levelControler; _rb = GetComponent <Rigidbody>(); _model = transform.Find("Model"); _trackController = currentTrack; _playerConfig = playerConfig; _playerData = new PlayerData(); _playerData.TimeAccelerated = 0; _intervalStart = _trackController.GetCurrentTrackPoint(); transform.position = _intervalStart.Start.position; _isReady = true; _canMove = true; }