Example #1
0
    private Vector3 CalculateAgentForce()
    {
        if (explosion < 10)
        {
            return(Vector3.zero);
        }

        var force = Vector3.zero;

        /*
         * foreach(var agent in perceivedNeighbors)
         * {
         *  if (!AgentManager.IsAgent(agent))
         *  {
         *      continue;
         *  }
         *      var neighbor = AgentManager.agentsObjs[agent];
         *      var dir = (transform.position - neighbor.transform.position).normalized;
         *      var overlap = (radius + neighbor.radius) - Vector3.Distance(transform.position, agent.transform.position);
         *      var tangent = Vector3.Cross(Vector3.up, dir);
         *
         *      force += Parameters.A * Mathf.Exp(overlap / Parameters.B) * dir; //proximityForce
         *      force += Parameters.k * Mathf.Max(overlap, 0) * dir; //repultionForce
         *      force += Parameters.Kappa * Mathf.Max(overlap, 0) * Vector3.Dot(rb.velocity - neighbor.GetVelocity(), tangent) * tangent; //slidingForce
         * }
         */
        int     g;
        Vector3 n = new Vector3();
        Vector3 t = new Vector3();

        foreach (var agent in perceivedNeighbors)
        {
            if (!PEManager.IsAgent(agent))
            {
                continue;
            }

            n = transform.position - agent.transform.position;
            n.Normalize();
            t = Vector3.Cross(Vector3.up, n);

            if (Vector3.Distance(transform.position, agent.transform.position) <= (nma.radius + agent.GetComponent <NavMeshAgent>().radius))
            {
                g = 1;
            }
            else
            {
                g = 0;
            }
            force += ((Parameters.A * Mathf.Exp(((nma.radius + agent.GetComponent <NavMeshAgent>().radius) - Vector3.Distance(transform.position, agent.transform.position)) / Parameters.B) + (Parameters.k * g)) * n); //proximityForce + repulsionForce
            force += (Parameters.Kappa * g * Vector3.Dot((agent.GetComponent <Rigidbody>().velocity - GetVelocity()), t) * t);                                                                                           //slidingForce
        }

        return(force);
    }
Example #2
0
 public void OnTriggerEnter(Collider other)
 {
     if (PEManager.IsAgent(other.gameObject))
     {
         perceivedNeighbors.Add(other.gameObject);
     }
     if (WallManager.IsWall(other.gameObject) || other.CompareTag("wall"))
     {
         adjacentWalls.Add(other.gameObject);
     }
 }