コード例 #1
0
    private void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent <Humanoid>();

        targetSeen = false;
        isFiring   = false;
        Object[] potentialTargets =
            Resources.FindObjectsOfTypeAll(typeof(GameObject));
        foreach (object obj in potentialTargets)
        {
            GameObject go     = (GameObject)obj;
            Humanoid   test_H = go.GetComponent <Humanoid>();
            if (test_H != null)
            {
                // object instance comparison wasn't working.
                // object scene names are unique.
                if (test_H.name != self.name)
                {
                    Stimulus.origin test_S = test_H.GetOriginOfStimulus();

                    if (test_S == sight.getDesiredTarget())// && !targets.Contains(test_H))
                    {
                        targets.Add(test_H);
                    }
                }
            }
        }
        target = ChooseNewTarget();
        // Debug.Log(target);
    }
コード例 #2
0
    private void Copy()
    {
        Mesh closestMesh = baseMesh;

        Stimulus.origin meshStimulusOrigin = Stimulus.origin.Patient;
        float           minDist            = Mathf.Infinity;

        // in case player is an object and activates power while sneaking.
        movingObject = false;

        foreach (ICopyable copyable in Copyables)
        {
            Vector3 positionOfCopyable = copyable.GetPosition();

            float testDist = Vector3.Distance(transform.position,
                                              positionOfCopyable);

            if (minDist > testDist)
            {
                Ray testLineOfSight = new Ray();

                testLineOfSight.origin    = transform.position;
                testLineOfSight.direction =
                    positionOfCopyable - transform.position;

                RaycastHit hit;

                // test if the copyable can be seen by the player
                if (Physics.Raycast(testLineOfSight, out hit))
                {
                    ICopyable testCopyable =
                        hit.transform.gameObject.GetComponent <ICopyable>();

                    if (testCopyable != null)
                    {
                        minDist            = testDist;
                        closestMesh        = testCopyable.GetMesh();
                        meshStimulusOrigin = testCopyable.GetOriginOfStimulus();
                        // copiedPower = testCopyable.GetPower();
                    }
                }
            }
        }

        if (minDist > 5f)
        {
            closestMesh        = baseMesh;
            meshStimulusOrigin = Stimulus.origin.Patient;
        }

        GetComponent <MeshFilter>().mesh = closestMesh;
        stimulus.SetCurrentOrigin(meshStimulusOrigin);
    }
コード例 #3
0
    void OnTriggerEnter(Collider other)
    {
        Stimulus stimulus = other.GetComponent <Stimulus>();

        if (stimulus != null)
        {
            Stimulus.origin currentOrigin = stimulus.GetCurrentOrigin();
            //Check the aspect
            if (currentOrigin == desiredStimulusOrigin ||
                currentOrigin == Stimulus.origin.Sneaking)
            {
                print("Touched " + desiredStimulusOrigin + "!");
                patientTouched = true;
            }
        }
    }
コード例 #4
0
 //Detect perspective field of view for the AI Character
 void DetectAspect()
 {
     foreach (Humanoid h in humanoids)
     {
         RaycastHit hit;
         Vector3    rayDirection;
         //Direction from current position to player position
         rayDirection = h.GetPosition() - transform.position;
         int FieldOfView  = 60;
         int ViewDistance = 100;
         //Check the angle between the AI character's forward
         //vector and the direction vector between player and AI
         if ((Vector3.Angle(rayDirection, transform.forward)) < FieldOfView)
         {
             // Detect if player is within the field of view
             if (Physics.Raycast(transform.position, rayDirection,
                                 out hit, ViewDistance))
             {
                 // testing Stimulus even after initialization ensures the
                 // correct types of humanoids are added to the the
                 // 'humanoid' list, because copycat can change his
                 // stimulus type and all characters can crouch.
                 Stimulus stimulus = hit.collider.GetComponent <Stimulus>();
                 if (stimulus != null)
                 {
                     Stimulus.origin currentOrigin = stimulus.GetCurrentOrigin();
                     //Check the origin of the stimulus.
                     // Ignore. “Sneaking” players CAN be seen.
                     if (currentOrigin == desiredStimulusOrigin ||
                         currentOrigin == Stimulus.origin.Sneaking)
                     {
                         print(desiredStimulusOrigin + " seen!");
                         // print(playerTrans.transform.gameObject.name);
                         seenTarget = h;
                         targetSeen = true;
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
    //Detect perspective field of view for the AI Character
    void DetectAspect()
    {
        RaycastHit hit;

        rayDirection = playerTrans.position - transform.position;

        if (Physics.Raycast(transform.position, rayDirection,
                            out hit, SoundDistance))
        {
            Stimulus stimulus = hit.collider.GetComponent <Stimulus>();
            if (stimulus != null)
            {
                Stimulus.origin currentOrigin = stimulus.GetCurrentOrigin();
                //Check the aspect
                if (currentOrigin == desiredStimulusOrigin)
                {
                    print("Heard target.");
                    patientHeard = true;
                }
            }
        }
    }