Example #1
0
        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();
        }
Example #2
0
        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();
                        }
                    }
                }
            }
        }
Example #3
0
        public void Spawn(bool isHeld)
        {
            _animator.SetTrigger(SpawnTrigger);

            if (isHeld)
            {
                _state = CubimalState.Airborne;
            }
        }
Example #4
0
 public void StartRace(Vector3 destination)
 {
     if (CanMove())
     {
         StartMoving(destination);
     }
     else
     {
         _state = CubimalState.Settled;
         _rigidbody.isKinematic = false;
     }
 }
Example #5
0
        private void StopMoving()
        {
            _state      = CubimalState.Settled;
            _isSettling = false;

            _navMeshAgent.enabled = false;
            _animator.SetBool(IsRacingBool, false);

            _key.StopUnwinding();
            _destination = Vector3.zero;

            OnStopped?.Invoke();
        }
Example #6
0
        private void OnAttachedToHand(Hand hand)
        {
            if (_stopUnwindingSequence != null)
            {
                StopCoroutine(_stopUnwindingSequence);
                _stopUnwindingSequence = null;
            }

            _state             = CubimalState.Held;
            _currentSettleTime = 0f;
            _isSettling        = false;

            StopMoving();

            OnPickedUp?.Invoke();
        }
Example #7
0
 private void OnDetachedFromHand(Hand hand)
 {
     _state             = CubimalState.Airborne;
     _currentSettleTime = 0f;
     _isSettling        = false;
 }
Example #8
0
 public void PositionForRace()
 {
     _state = CubimalState.Racing;
     _rigidbody.isKinematic = true;
 }