Example #1
0
    private IEnumerator FetchToPlayer()
    {
        fetching = true;
        yield return(new WaitForSeconds(1));

        int oldPriority = nav.avoidancePriority;

        nav.avoidancePriority = 0; // be able to push through other JoeJeffs
        Vector3 target = FetchTarget.Find().position;

        // walk to fetch target
        nav.SetDestination(target);
        yield return(new WaitForSeconds(1));

        // yield until reaches target
        while ((target - nav.transform.position).sqrMagnitude > 0.03f)
        {
            yield return(null);
        }
        // look at player
        useCustomLookDir = true;
        customLookDir    = Camera.main.transform.position - transform.position;
        customLookDir.y  = 0;
        yield return(new WaitForSeconds(1));

        //set up  throw force to reach a certain height in the current gravity
        float   throwHeight = 1f;
        float   throwForce  = Mathf.Sqrt(2 * -Physics.gravity.y * throwHeight);
        Vector3 throwVel    = new Vector3(0, throwForce, 0.5f);

        throwVel = transform.rotation * throwVel;
        if (carrier.carrying.GetComponent <CrowdTarget>() != null)
        {
            //disable crowd target so I don't immediately chase this thing again
            carrier.carrying.GetComponent <CrowdTarget>().active = false;
        }
        carrier.Throw(throwVel);
        yield return(new WaitForSeconds(0.5f));

        useCustomLookDir      = false;
        nav.avoidancePriority = oldPriority;
        fetching = false;
    }
Example #2
0
 private void Awake()
 {
     instance = this;
 }