Exemplo n.º 1
0
    EchidnaInteractable SearchForClosestInteractable(float withinDist)
    {
        //print("Searching for interactable: " + _InteractablesInRange.Count);

        EchidnaInteractable interactable = null;

        _InteractablesInRange.RemoveAll(item => item == null);

        if (_InteractablesInRange.Count > 0)
        {
            float closestDist = withinDist;
            // Look for interactable in range
            foreach (EchidnaInteractable e in _InteractablesInRange)
            {
                float newDist = Vector3.Distance(e.transform.position, transform.position);

                if (newDist < closestDist)
                {
                    closestDist  = newDist;
                    interactable = e;
                }
            }
        }

        return(interactable);
    }
Exemplo n.º 2
0
    void Consume(EchidnaInteractable interactable)
    {
        if (_Debug)
        {
            print(name + "Consumed: " + interactable.name);
        }

        if (interactable._Type == EchidnaInteractable.Type.Food)
        {
            _FullnessNorm += interactable._EffectStrength;

            //Audio
            Burp();
        }
        else if (interactable._Type == EchidnaInteractable.Type.Booze)
        {
            _DrunkenessNorm += interactable._EffectStrength;
            _AudioSource.playClip(_Drink);
            Invoke("Burp", 1);
        }

        _ConsumeDuration    = interactable.TimeToConsume;
        _ActiveInteractable = null;
        _InteractablesInRange.Remove(interactable);

        Destroy(interactable.gameObject);

        SetState(State.Consuming);
    }
Exemplo n.º 3
0
    void SetState(State state)
    {
        if (state == State.Idle)
        {
            _State                = state;
            _StateTimer           = 0;
            _StateTimeoutDuration = _IdleTimeoutDuration;

            EchidnaInteractable interactable = SearchForClosestInteractable(6);
            if (interactable != null)
            {
                _ActiveInteractable = interactable;
                SetState(State.Seeking);
            }
        }
        else if (state == State.BeingPushed)
        {
            _State                = state;
            _StateTimer           = 0;
            _StateTimeoutDuration = _PushingTimeoutDuration;

            PlayRollCont();
        }
        else if (state == State.Wander)
        {
            _State      = state;
            _StateTimer = 0;

            PlayRollCont();

            EchidnaInteractable interactable = SearchForClosestInteractable(9999);
            if (interactable != null)
            {
                _ActiveInteractable = interactable;
                SetState(State.Seeking);
            }
        }
        else if (state == State.Seeking)
        {
            _State      = state;
            _StateTimer = 0;
        }
        else if (state == State.Consuming)
        {
            _State      = state;
            _StateTimer = 0;
        }

        if (_Debug)
        {
            print(name + " State set to: " + _State.ToString());
        }
    }
Exemplo n.º 4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        _PushingCount = 0;
        if (_Players[0]._State == PlayerController.State.PushingEchidna)
        {
            _PushingCount++;
        }
        if (_Players[1]._State == PlayerController.State.PushingEchidna)
        {
            _PushingCount++;
        }

        if (_State == State.Idle)
        {
            // Don't move while idle timer accumulates
            _StateTimer += Time.deltaTime;

            // If idle timeout is up then start to wander
            if (_StateTimer >= _StateTimeoutDuration)
            {
                SetState(State.Wander);
            }
        }
        else if (_State == State.BeingPushed)
        {
            //LimitVelocity();
            _RB.AddForce(GetPerlinForce(transform.position, _BasePerlfieldScaler, _BasePerlForceScaler, _PerlinOffset) * _DrunkenessNorm * .4f);


            // Don't move while idle timer accumulates
            _StateTimer += Time.deltaTime;

            // If idle timeout is up then start to wander
            if (_StateTimer >= _StateTimeoutDuration)
            {
                SetState(State.Idle);
            }
        }
        else if (_State == State.Wander)
        {
            // Wander aimlessly until you come across a distraction
            _PerlOffset = Time.time * .1f;
            AddPerlinForce(transform.position, _BasePerlfieldScaler, _BasePerlForceScaler, _PerlOffset);


            // Search for closest interactabl;e
            EchidnaInteractable interactable = SearchForClosestInteractable(999);
            if (interactable != null)
            {
                _ActiveInteractable = interactable;
                SetState(State.Seeking);
            }
        }
        else if (_State == State.Seeking)
        {
            _RB.AddForce(GetDirectionTowardInteractable());
            // Seek toward target distraction
        }
        else if (_State == State.Consuming)
        {
            // Don't move while idle timer accumulates
            _StateTimer += Time.deltaTime;

            // If idle timeout is up then start to wander
            if (_StateTimer >= _StateTimeoutDuration)
            {
                if (_Debug)
                {
                    print(name + " consuming finsihed with timer at: " + _StateTimer + "   " + _StateTimeoutDuration);
                }
                SetState(State.Wander);
            }
        }

        if (_AudioSource.clip == _RollLoop)
        {
            _AudioSource.volume = _RB.velocity.magnitude.ScaleTo01(0, 3) * .7f;
        }

        LimitVelocity();

        if (ExperienceManager.Instance != null)
        {
            ExperienceManager.Instance._EchidnaDebug.text = "Echidna - State: " + _State + "  objects in range: " + _InteractablesInRange.Count + "Timer: " + _StateTimer + " / " + _StateTimeoutDuration;
        }
    }