Exemplo n.º 1
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.layer != LayerMask.NameToLayer("PikminInteractable"))
        {
            return;
        }

        if (_TargetObjectCollider != null && collision.collider == _TargetObjectCollider)
        {
            CarryoutIntention();
        }

        if (_CurrentState == PikminStates.Thrown)
        {
            _TargetObject         = collision.transform;
            _TargetObjectCollider = collision.collider;
            _Intention            = collision.gameObject.GetComponent <IPikminInteractable> ().IntentionType;
            CarryoutIntention();
        }
    }
Exemplo n.º 2
0
    void CarryoutIntention()
    {
        PikminStates previousState = _CurrentState;

        // Run intention-specific logic (attack = OnAttackStart for the target object)
        switch (_Intention)
        {
        case PikminIntention.Attack:
            _AttackingTransform = _TargetObject;

            _Attacking = _TargetObject.GetComponent <IPikminAttack> ();
            _Attacking.OnAttackStart(this);

            LatchOnto(_AttackingTransform);

            ChangeState(PikminStates.Attacking);
            break;

        case PikminIntention.Carry:
            break;

        case PikminIntention.PullWeeds:
            break;

        case PikminIntention.Idle:
            ChangeState(PikminStates.Idle);
            break;

        default:
            break;
        }

        if (previousState == _CurrentState && _CurrentState != PikminStates.Idle)
        {
            ChangeState(PikminStates.Idle);
        }

        _Intention = PikminIntention.Idle;
    }
Exemplo n.º 3
0
    void HandleIdle()
    {
        // Look for a target object
        Collider[] objects = Physics.OverlapSphere(transform.position, _Data._SearchRadius, _PikminInteractableMask);
        foreach (Collider collider in objects)
        {
            // Check if the object can even be seen by the Pikmin
            Vector3 closestPointToPikmin = collider.ClosestPoint(transform.position);
            if (Physics.Raycast(transform.position, (closestPointToPikmin - transform.position).normalized, out RaycastHit hit, _Data._SearchRadius) &&
                // See if the Collider we hit wasn't the Player OR the closest object, meaning we can't actually get to the object
                hit.collider != collider &&
                hit.transform.CompareTag("Player") == false)
            {
                continue;
            }

            // We can move to the target object, and it is an interactable, so set our target object
            ChangeState(PikminStates.RunningTowards);
            _TargetObject         = collider.transform;
            _TargetObjectCollider = collider;
            _Intention            = collider.GetComponent <IPikminInteractable> ().IntentionType;
        }
    }