예제 #1
0
        void Damaged(Damageable.DamageMessage damageMessage)
        {
            m_Animator.SetTrigger(m_HashHurt);

            Vector3 forward = damageMessage.damageSource - transform.position;

            forward.y = 0;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.y);

            //shake the camera


            //播放受伤音效
        }
예제 #2
0
        public void Death(Damageable.DamageMessage msg)
        {
            Vector3 pushForce = transform.position - msg.damageSource;

            pushForce.y = 0;

            transform.forward = -pushForce.normalized;
            //controller.AddForce(pushForce.normalized * 7.0f - Physics.gravity * 0.6f);

            controller.animator.SetTrigger(hashHit);
            controller.animator.SetTrigger(hashThrown);

            //We unparent the deathAudio source, as it would destroy it with the gameobject when it get replaced by the ragdol otherwise
            deathAudio.transform.SetParent(null, true);
            deathAudio.PlayRandomClip();

            GameObject.Destroy(deathAudio, deathAudio.clip == null ? 0.0f : deathAudio.clip.length + 0.5f);
        }
        // Called by Ellen's Damageable when she is hurt.
        public void OnReceiveMessage(MessageType type, object sender, object data)
        {
            switch (type)
            {
            case MessageType.DAMAGED:
            {
                Damageable.DamageMessage damageData = (Damageable.DamageMessage)data;
                Damaged(damageData);
            }
            break;

            case MessageType.DEAD:
            {
                Damageable.DamageMessage damageData = (Damageable.DamageMessage)data;
                Die(damageData);
            }
            break;
            }
        }
        private void OnTriggerStay(Collider other)
        {
            var d = other.GetComponent <Damageable>();

            if (d == null)
            {
                return;
            }

            var msg = new Damageable.DamageMessage()
            {
                amount     = damageAmount,
                damager    = this,
                direction  = Vector3.up,
                stopCamera = stopCamera
            };

            d.ApplyDamage(msg);
        }
예제 #5
0
        public void BeHit(int decHP, ICreatureBehavior source)
        {
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = source.GetTransform().position - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            var msg = new Damageable.DamageMessage()
            {
                amount     = decHP,
                damager    = this,
                direction  = Vector3.up,
                stopCamera = false
            };

            m_Damageable.ApplyDamage(msg);

            if (IsMine)
            {
                // Shake the camera.
                CameraShake.Shake(CameraShake.k_PlayerHitShakeAmount, CameraShake.k_PlayerHitShakeTime);

                // Play an audio clip of being hurt.
                if (hurtAudioPlayer != null)
                {
                    hurtAudioPlayer.PlayRandomClip();
                }
                if (m_healthUI != null)
                {
                    m_healthUI.ChangeHitPointUI(m_Damageable);
                }
            }
        }
        // Called by OnReceiveMessage.
        void Damaged(Damageable.DamageMessage damageMessage)
        {
            // Set the Hurt parameter of the animator.
            m_Animator.SetTrigger(m_HashHurt);

            // Find the direction of the damage.
            Vector3 forward = damageMessage.damageSource - transform.position;

            forward.y = 0f;

            Vector3 localHurt = transform.InverseTransformDirection(forward);

            // Set the HurtFromX and HurtFromY parameters of the animator based on the direction of the damage.
            m_Animator.SetFloat(m_HashHurtFromX, localHurt.x);
            m_Animator.SetFloat(m_HashHurtFromY, localHurt.z);

            // Play an audio clip of being hurt.
            if (hurtAudioPlayer != null)
            {
                hurtAudioPlayer.PlayRandomClip();
            }
        }
        public void Explosion()
        {
            if (explosionPlayer)
            {
                explosionPlayer.transform.SetParent(null);
                explosionPlayer.PlayRandomClip();
            }

            int count = Physics.OverlapSphereNonAlloc(transform.position, explosionRadius, m_ExplosionHitCache,
                                                      damageMask.value);

            Damageable.DamageMessage message = new Damageable.DamageMessage
            {
                amount       = damageAmount,
                damageSource = transform.position,
                damager      = this,
                stopCamera   = false,
                throwing     = true
            };


            for (int i = 0; i < count; ++i)
            {
                Damageable d = m_ExplosionHitCache[i].GetComponentInChildren <Damageable>();

                if (d != null)
                {
                    d.ApplyDamage(message);
                }
            }

            pool.Free(this);

            m_VFXInstance.gameObject.transform.position = transform.position;
            m_VFXInstance.time = 0.0f;
            m_VFXInstance.gameObject.SetActive(true);
            m_VFXInstance.Play(true);
        }
        private void OnTriggerStay(Collider other)
        {
            if ((damagedLayers.value & 1 << other.gameObject.layer) == 0)
            {
                return;
            }

            Damageable d = other.GetComponentInChildren <Damageable>();

            if (d != null && !d.isInvulnerable)
            {
                Damageable.DamageMessage message = new Damageable.DamageMessage
                {
                    damageSource = transform.position,
                    damager      = this,
                    amount       = amount,
                    direction    = (other.transform.position - transform.position).normalized,
                    throwing     = false
                };

                d.ApplyDamage(message);
            }
        }
예제 #9
0
        public void ApplyDamage(Damageable.DamageMessage msg)
        {
            //TODO : make that more generic, (e.g. move it to the MeleeWeapon code with a boolean to enable shaking of camera on hit?)
            //if (msg.damager.name == "Staff")
            //    CameraShake.Shake(0.06f, 0.1f);

            float verticalDot   = Vector3.Dot(Vector3.up, msg.direction);
            float horizontalDot = Vector3.Dot(transform.right, msg.direction);

            Vector3 pushForce = transform.position - msg.damageSource;

            pushForce.y = 0;

            transform.forward = -pushForce.normalized;
            controller.AddForce(pushForce.normalized * 5.5f, false);

            controller.animator.SetFloat(hashVerticalDot, verticalDot);
            controller.animator.SetFloat(hashHorizontalDot, horizontalDot);

            controller.animator.SetTrigger(hashHit);

            hitAudio.PlayRandomClip();
        }
예제 #10
0
        public void Death(Damageable.DamageMessage msg)
        {
            //Vector3 pushForce = transform.position - msg.damageSource;

            //pushForce.y = 0;

            //transform.forward = -pushForce.normalized;
            //controller.AddForce(pushForce.normalized * 7.0f - Physics.gravity * 0.6f);

            controller.animator.SetTrigger(Die);
            if (HealOnDeath && Target != null)
            {
                Target.gameObject.GetComponent <Damageable>().Heal(1, 1);
            }

            //We unparent the hit source, as it would destroy it with the gameobject when it get replaced by the ragdol otherwise
            if (DeathAudio != null)
            {
                DeathAudio.transform.SetParent(null, true);
                DeathAudio.PlayRandomClip();
                Destroy(DeathAudio, DeathAudio.clip == null ? 0.0f : DeathAudio.clip.length + 0.5f);
            }
        }
예제 #11
0
        public void ApplyDamage(Damageable.DamageMessage msg)
        {
            if (msg.damager.name == "Staff")
            {
                CameraShake.Shake(0.06f, 0.1f);
            }

            float verticalDot   = Vector3.Dot(Vector3.up, msg.direction);
            float horizontalDot = Vector3.Dot(transform.right, msg.direction);

            Vector3 pushForce = transform.position - msg.damageSource;

            pushForce.y = 0;

            transform.forward = -pushForce.normalized;
            controller.AddForce(pushForce.normalized * 5.5f, false);

            controller.animator.SetFloat(hashVerticalDot, verticalDot);
            controller.animator.SetFloat(hashHorizontalDot, horizontalDot);

            controller.animator.SetTrigger(hashHit);

            hitAudio.PlayRandomClip();
        }
예제 #12
0
        // Called by Ellen's Damageable when she is hurt.
        public void OnReceiveMessage(MsgType type, object sender, object data)
        {
            switch (type)
            {
            case MsgType.DAMAGED:
            {
                Damageable.DamageMessage damageData = (Damageable.DamageMessage)data;
                Damaged(damageData);
            }
            break;

            case MsgType.DEAD:
            {
                // frontend does not know the actual HP of other players
                if (!IsMine)
                {
                    return;
                }
                Damageable.DamageMessage damageData = (Damageable.DamageMessage)data;
                Die(damageData);
            }
            break;
            }
        }