public void StartMoving(Vector3 overrideDestination = default) { _state = CubimalState.Moving; if (IsStanding()) { if (overrideDestination != default) { _destination = overrideDestination; } else { _destination = transform.position + transform.forward * (_key.NormalisedWindAmount * MAX_DISTANCE); } _navMeshAgent.enabled = true; _navMeshAgent.speed = Random.Range(MIN_SPEED, MAX_SPEED); _navMeshAgent.SetDestination(_destination); } else { _stopUnwindingSequence = StartCoroutine(StopUnwinding()); } _animator.SetBool(IsRacingBool, true); _key.StartUnwinding(); }
private void Update() { if (_state == CubimalState.Moving) { if (Vector3.Distance(transform.position, _destination) <= DESTINATION_REACHED_DISTANCE || !_navMeshAgent.hasPath) { StopMoving(); } } else if (_state == CubimalState.Airborne) { if (_isSettling) { _currentSettleTime += Time.deltaTime; if (_currentSettleTime >= SETTLE_TIME) { _state = CubimalState.Settled; _isSettling = false; if (CanMove()) { StartMoving(); } } } } }
public void Spawn(bool isHeld) { _animator.SetTrigger(SpawnTrigger); if (isHeld) { _state = CubimalState.Airborne; } }
public void StartRace(Vector3 destination) { if (CanMove()) { StartMoving(destination); } else { _state = CubimalState.Settled; _rigidbody.isKinematic = false; } }
private void StopMoving() { _state = CubimalState.Settled; _isSettling = false; _navMeshAgent.enabled = false; _animator.SetBool(IsRacingBool, false); _key.StopUnwinding(); _destination = Vector3.zero; OnStopped?.Invoke(); }
private void OnAttachedToHand(Hand hand) { if (_stopUnwindingSequence != null) { StopCoroutine(_stopUnwindingSequence); _stopUnwindingSequence = null; } _state = CubimalState.Held; _currentSettleTime = 0f; _isSettling = false; StopMoving(); OnPickedUp?.Invoke(); }
private void OnDetachedFromHand(Hand hand) { _state = CubimalState.Airborne; _currentSettleTime = 0f; _isSettling = false; }
public void PositionForRace() { _state = CubimalState.Racing; _rigidbody.isKinematic = true; }