Example #1
0
    /// <summary>
    /// Physics Update
    /// </summary>
    void FixedUpdate()
    {
        foreach (GameObject agent in agents)
        {
            if (agent != null)
            {
                AgentPredictiveAvoidanceModel agentOther = agent.GetComponent <AgentPredictiveAvoidanceModel> ();
                Rigidbody agentRigidBody = agent.GetComponent <Rigidbody> ();
                Transform agentTransform = agent.GetComponent <Transform> ();

                float idealWallDistance = agentOther.agentRadius + wallDistance;
                float safe = idealWallDistance * idealWallDistance;

                wall_normal = calc_wall_normal(agentTransform, box1);
                Pair <Vector3, Vector3> line_p = calcWallPointsFromNormal(box1, wall_normal);
                Vector3 n_w = agentTransform.position - closestPointLineSegment(line_p.First, line_p.Second, agentTransform.position);


                //Debug.DrawLine (line_p.First, line_p.Second, Color.blue, 0.02f);

                //Debug.DrawLine (new Vector3(5, 0, box1.zmin), new Vector3(5, 0, box1.zmax), Color.red, 0.02f);

                float d_w = n_w.sqrMagnitude;

                if (d_w < safe)
                {
                    d_w = Mathf.Sqrt(d_w);
                    if (d_w > 0)
                    {
                        n_w /= d_w;
                    }

                    float distanceMinimumRadius = (d_w - agentOther.agentRadius) < 0.001f ? 0.001f : d_w - agentOther.agentRadius;
                    //Debug.Log("idealWallDistance: " + idealWallDistance);
                    //Debug.Log("d_w: " + d_w);
                    //Debug.Log("distanceMinimumRadius: " + distanceMinimumRadius);
                    //Debug.Log("n_w.magnitude: " + n_w.magnitude);
                    //Debug.Log("Final Magnitude: " + (idealWallDistance - d_w) / Mathf.Pow(distanceMinimumRadius, wallSteepness));
                    Vector3 drivingForce = (idealWallDistance - d_w) / Mathf.Pow(distanceMinimumRadius, wallSteepness) * n_w;

                    //Debug.DrawLine(agentTransform.position, agentTransform.position + drivingForce, Color.blue, 0.02f);
                    agentRigidBody.AddForce(drivingForce, ForceMode.Force);

                    // MELISSA check HERE
                    DistractedAgent distractionScript = agent.GetComponent <DistractedAgent>();
                    if (distractionScript != null)
                    {
                        distractionScript.PayAttention();
                    }
                }
            }
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        var agentAI = this.transform.GetComponent <Agent> ();

        if (agentAI.GetAgentType() == "Normative")
        {
            NormativeAgent normativeAgentScript = GetComponent <NormativeAgent> ();
            normativeAgentScript.SetTarget(target);
        }
        else if (agentAI.GetAgentType() == "Distracted")
        {
            DistractedAgent distractedAgentScript = GetComponent <DistractedAgent> ();
            distractedAgentScript.SetTarget(target);
        }
    }