Ejemplo n.º 1
0
        private void GetClosestThreat()
        {
            float closest          = -1;
            var   previousTarget   = m_target;
            bool  isNewTargetFound = false;

            for (int i = 0; i < m_threatList.Count; i++)
            {
                float currentDist = StaticUtil.FastDistance(this.transform.position, m_threatList[i].transform.position);
                if (currentDist > closest)
                {
                    closest = currentDist;
                    if (m_target != m_threatList[i] && !m_threatList[i].isDead)
                    {
                        m_target = m_threatList[i];

                        if (m_target != previousTarget)
                        {
                            m_attackRangeModifier = m_target.GetComponent <AgentAttackRangeModifier>();
                        }

                        isNewTargetFound = true;
                    }
                }
            }

            if (m_target.isDead && !isNewTargetFound)
            {
                m_target = m_treeOfLife;
            }
        }
Ejemplo n.º 2
0
 private void AlertOnHit(vCharacter attacker)
 {
     if (attacker)
     {
         m_target = attacker;
         StartChase();
     }
 }
Ejemplo n.º 3
0
        private void StartChase(vCharacter target)
        {
            m_target = target;

            var col       = target.GetComponent <Collider>();
            var colBounds = col.bounds;

            m_targetColliderLength = colBounds.extents;

            m_mood = Mood.Chase;
        }
Ejemplo n.º 4
0
 void Start()
 {
     iChar = transform.GetComponentInParent <vCharacter>();
     if (iChar == null)
     {
         Debug.LogWarning("The character must have a ICharacter Interface");
         Destroy(this.gameObject);
     }
     healthSlider.maxValue = iChar.maxHealth;
     healthSlider.value    = healthSlider.maxValue;
     damageDelay.maxValue  = iChar.maxHealth;
     damageDelay.value     = healthSlider.maxValue;
     damageCounter.text    = string.Empty;
 }
Ejemplo n.º 5
0
    void Start()
    {
        if (!sensor)
        {
            var sensorObj = new GameObject("HeadTrackSensor");
            sensor = sensorObj.AddComponent <vHeadTrackSensor>();
        }

        vchar = GetComponent <vCharacter>();

        sensor.headTrack = this;
        animator         = GetComponentInParent <Animator>();
        head             = animator.GetBoneTransform(HumanBodyBones.Head);
        var spine1 = animator.GetBoneTransform(HumanBodyBones.Spine);
        var spine2 = animator.GetBoneTransform(HumanBodyBones.Chest);

        spines = new List <Transform>();
        spines.Add(spine1);
        spines.Add(spine2);
        var neck = animator.GetBoneTransform(HumanBodyBones.Neck);

        if (neck.parent != spine2)
        {
            spines.Add(neck.parent);
        }

        if (head)
        {
            headHeight = Vector3.Distance(transform.position, head.position);
            sensor.transform.position = head.transform.position;
        }
        else
        {
            sensor.transform.position = transform.position;
        }

        var layer = LayerMask.NameToLayer("HeadTrack");

        sensor.transform.parent = transform;
        sensor.gameObject.layer = layer;
        sensor.gameObject.tag   = transform.tag;
        tagsHash = new List <int>();

        for (int i = 0; i < animatorTags.Count; i++)
        {
            tagsHash.Add(Animator.StringToHash(animatorTags[i]));
        }
        GetLookPoint();
    }
Ejemplo n.º 6
0
        private void DefineAsThreat(vCharacter target)     // add a subject to the threat list
        {
            if (m_threatList.Contains(target))
            {
                if (target.isDead)
                {
                    m_threatList.Remove(target);
                }
                else
                {
                    return;
                }
            }

            m_threatList.Add(target);
        }
Ejemplo n.º 7
0
        void Start()
        {
            // store the Animator component
            animator = GetComponent <Animator>();
            iChar    = GetComponent <vCharacter>();

            if (iChar)
            {
                iChar.onActiveRagdoll.AddListener(ActivateRagdoll);
            }

            // find character chest and hips
            characterChest = animator.GetBoneTransform(HumanBodyBones.Chest);
            characterHips  = animator.GetBoneTransform(HumanBodyBones.Hips);
            hipsParent     = characterHips.parent;
            // set all RigidBodies to kinematic so that they can be controlled with Mecanim
            // and there will be no glitches when transitioning to a ragdoll
            setKinematic(true);
            setCollider(true);

            // find all the transforms in the character, assuming that this script is attached to the root
            Component[] components = GetComponentsInChildren(typeof(Transform));

            // for each of the transforms, create a BodyPart instance and store the transform
            foreach (Component c in components)
            {
                if (!ignoreTags.Contains(c.tag))
                {
                    BodyPart bodyPart = new BodyPart();
                    bodyPart.transform = c as Transform;
                    if (c.GetComponent <Rigidbody>() != null)
                    {
                        c.tag = gameObject.tag;
                    }
                    bodyParts.Add(bodyPart);
                }
            }
        }
Ejemplo n.º 8
0
 public void OnReceiveAttack(vDamage damage, vIMeleeFighter attacker)
 {
     if (ragdoll && !ragdoll.iChar.isDead)
     {
         var _damage = new vDamage(damage);
         var value   = (float)_damage.damageValue;
         _damage.damageValue = (int)(value * damageMultiplier);
         ragdoll.gameObject.ApplyDamage(_damage, attacker);
     }
     else
     {
         if (!iChar)
         {
             iChar = GetComponentInParent <vCharacter>();
         }
         if (iChar)
         {
             var _damage = new vDamage(damage);
             var value   = (float)_damage.damageValue;
             _damage.damageValue = (int)(value * damageMultiplier);
             iChar.gameObject.ApplyDamage(_damage, attacker);
         }
     }
 }
Ejemplo n.º 9
0
        private void Awake()
        {
            m_mood       = Mood.Wander;
            m_lastScan   = Time.time;
            m_lastWander = Time.time;
            m_startPos   = this.transform.position;
            m_entity     = GetComponent <vCharacter>();
            m_agent      = GetComponent <NavMeshAgent>();
            m_animator   = GetComponent <Animator>();

            //TODO Fix
            //m_entity.OnAttackedAlert += AlertOnHit;
            m_moveSpeed = Random.Range(1.3f, 3f);

            m_treeOfLife = FindObjectOfType <TreeOfLife>();

            if (m_treeOfLife)
            {
                m_target = m_treeOfLife.GetComponent <vCharacter>();
            }

            AgentConfigure();
            AnimatorConfigure();
        }
Ejemplo n.º 10
0
 void Start()
 {
     _rigidbody = GetComponent <Rigidbody>();
     character  = GetComponent <vCharacter>();
 }
Ejemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     chara = GetComponent <vCharacter> ();
 }
Ejemplo n.º 12
0
 void Start()
 {
     _rigidbody = GetComponent <Rigidbody>();
     character  = GetComponent <vCharacter>();
     character.onReceiveDamage.AddListener(TakeDamage);
 }