Exemplo n.º 1
0
    void UpdateAttractor()
    {
        if (Leader == null || Leader == this.gameObject) //if this agent is the leader himself
        {
            agentComponent.SteerTo(agentComponent.attractor.transform.position);
        }

        else if (Leader != null)
        {
            agentComponent.SteerTo(Leader.transform.position);
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (agentComponent.IsWounded() || oAgentComponent.IsWounded())
        {
            UpdateAppraisalStatus();
            endTime = Time.time;
            FinishFight();
        }
        else
        {
            if (oAgentComponent.role == (int)RoleName.Police)
            {
                agentComponent.AddDamage(0.1f);             //extra damage if opponent is a police
            }
            else
            {
                agentComponent.AddDamage(0.05f);
            }

            agentComponent.SteerTo(opponent.transform.position);
            transform.rotation = Quaternion.LookRotation(opponent.transform.position - transform.position, Vector3.up);

            //Send message to others to watch this fight
            foreach (GameObject c in agentComponent.collidingAgents)
            {
                if (c.GetComponent <AgentComponent>().role == (int)RoleName.Protester && c.GetComponent <AgentComponent>().IsVisible(this.gameObject, Mathf.PI / 2f) &&
                    c.GetComponent <AgentComponent>().IsFighting() == false && c.GetComponent <ProtesterBehavior>().isWatchingFight == false)
                {
                    if (c.GetComponent <AffectComponent>().personality[(int)OCEAN.E] > 0)   //intervene if assertive
                    {
                        c.GetComponent <AgentComponent>().SteerTo((transform.position + opponent.transform.position) / 2f);
                        watchers.Add(c);
                        c.GetComponent <ProtesterBehavior>().isWatchingFight = true;
                    }
                    else if (c.GetComponent <AffectComponent>().personality[(int)OCEAN.O] > 0) //watch if curious
                    {
                        c.GetComponent <SteeringController>().Stop(true);
                        c.GetComponent <AgentComponent>().Watch((transform.position + opponent.transform.position) / 2f);
                        watchers.Add(c);
                        c.GetComponent <ProtesterBehavior>().isWatchingFight = true;
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (agentComponent.IsDead())
        {
            shield.SetActiveRecursively(false);
            return;
        }


        UpdateAction();

        if (agentComponent.IsFighting() == false)
        {
            // if (intruder == null && (post - transform.position).magnitude > 1f) //if no one to watch && stop jittering
            if ((post - transform.position).magnitude > 2f) //if no one to watch && stop jittering
            {
                agentComponent.SteerTo(post);
            }
            // else
            //   agentComponent.GetComponent<NavMeshAgent>().Stop();
            Vigil();
        }
    }
Exemplo n.º 4
0
    void UpdateAttractor()
    {
        //Find closest object with the least number of people headed towards
        GameObject objs       = GameObject.Find("Objects");
        int        objCnt     = objs.transform.GetChildCount();
        Transform  closestObj = null;
        float      minDist    = 100000f;

        totalObjCnt = 0;
        Vector3 tmpMeshPos = objMeshPos;

        if (isPicking)
        {
            hand = transform.Find("Hips/Spine/Spine1/Spine2/Spine3/Spine4/Neck/RightShoulder/RightArm/RightForeArm/RightHand/RightHandRing1");
            currentObj.position = hand.position - objMeshPos;
        }



        for (int i = 0; i < objCnt; i++)
        {
            Transform obj = objs.transform.GetChild(i);
            if (obj.gameObject.active == false || obj.GetComponent <ObjComponent>().achieved == true)
            {
                continue;
            }
            totalObjCnt++;
            MeshFilter[] mfs = obj.GetComponents <MeshFilter>();
            foreach (MeshFilter mf in mfs)
            {
                Mesh  m    = mf.mesh;
                float dist = (m.bounds.center + obj.transform.position - transform.position).magnitude;
                if (dist < minDist)
                {
                    destination = m.bounds.center + obj.transform.position;
                    tmpMeshPos  = m.bounds.center;
                    minDist     = dist;
                    closestObj  = obj;
                }
            }
        }

        if (totalObjCnt == 0 || acquiredObjCnt >= desiredObjCnt)          //Nothing left to buy
        {
            if (hasPaid || affectComponent.personality[(int)OCEAN.C] < 0) // go to exit without paying
            {
                destination = agentComponent.attractor.transform.position;
                UpdateAppraisalStatus();
            }
            else if (acquiredObjCnt > 0)
            {
                Pay();
                UpdateAppraisalStatus();
            }
        }
        else
        {
            desiredObj = closestObj;
            if (closestObj != null)
            {
                if (minDist < 3f)  //Pick up object
                {
                    isPicking = true;
                    closestObj.GetComponent <ObjComponent>().achieved = true;
                    if (currentObj != null)
                    {
                        currentObj.gameObject.SetActiveRecursively(false);
                    }
                    //a new object is obtained
                    currentObj = closestObj;
                    objMeshPos = tmpMeshPos;
                    // closestObj.position =  hand.position;
                    //closestObj.gameObject.SetActiveRecursively(false);
                    acquiredObjCnt++;
                    UpdateAppraisalStatus();
                    UpdateAppraisalStatusOfOthers();
                }
            }
        }

        agentComponent.SteerTo(destination);
    }