Example #1
0
        /// <summary>
        /// The object has collided with another object.
        /// </summary>
        /// <param name="hit">The RaycastHit of the object. Can be null.</param>
        protected override void OnCollision(RaycastHit?hit)
        {
            base.OnCollision(hit);

            if (!hit.HasValue)
            {
                return;
            }

            m_MagicItem.PerformImpact(m_CastID, m_GameObject, hit.Value.transform.gameObject, hit.Value);
        }
Example #2
0
        /// <summary>
        /// A particle has collided with another object.
        /// </summary>
        /// <param name="other">The object that the particle collided with.</param>
        public void OnParticleCollision(GameObject other)
        {
            // If the transform is null the particle hasn't been initialized yet.
            if (m_Transform == null)
            {
                return;
            }

            // Prevent the particle from colliding with the originator.
            if (!m_CanCollideWithOriginator)
            {
                var characterLocomotion = other.GetCachedComponent <Character.UltimateCharacterLocomotion>();
                if (characterLocomotion != null && m_MagicItem.Character == characterLocomotion.gameObject)
                {
                    return;
                }
            }

            // PerformImpact requires a RaycastHit.
            var colliders = other.GetCachedComponents <Collider>();

            if (colliders == null)
            {
                return;
            }
            for (int i = 0; i < colliders.Length; ++i)
            {
                if (colliders[i].isTrigger)
                {
                    continue;
                }
                Vector3 closestPoint;
                if (colliders[i] is BoxCollider || colliders[i] is SphereCollider || colliders[i] is CapsuleCollider || (colliders[i] is MeshCollider && (colliders[i] as MeshCollider).convex))
                {
                    closestPoint = colliders[i].ClosestPoint(m_Transform.position);
                }
                else
                {
                    closestPoint = m_Transform.position;
                }
                var direction = other.transform.position - closestPoint;
                if (Physics.Raycast(closestPoint - direction.normalized * 0.1f, direction.normalized, out var hit, direction.magnitude + 0.1f, 1 << other.layer))
                {
                    m_MagicItem.PerformImpact(m_CastID, m_GameObject, other, hit);
                    break;
                }
            }
        }
Example #3
0
        /// <summary>
        /// The object has collided with another object.
        /// </summary>
        /// <param name="hit">The RaycastHit of the object. Can be null.</param>
        protected override void OnCollision(RaycastHit?hit)
        {
            base.OnCollision(hit);

            if (!hit.HasValue)
            {
                return;
            }

            m_MagicItem.PerformImpact(m_CastID, m_GameObject, hit.Value.transform.gameObject, hit.Value);

            // Destroys the projectile when it has collided with an object.
            if (m_DestroyOnCollision)
            {
                // The projectile can wait for any particles to stop emitting.
                var immediateDestroy = !m_WaitForParticleStop;
                if (!immediateDestroy)
                {
                    var particleSystem = m_GameObject.GetCachedComponent <ParticleSystem>();
                    if (particleSystem != null)
                    {
                        particleSystem.Stop(true, ParticleSystemStopBehavior.StopEmitting);
                        Scheduler.Schedule(particleSystem.main.duration, ReturnToObjectPool);
                        immediateDestroy = false;
                    }
                }
                if (immediateDestroy)
                {
                    ReturnToObjectPool();
                }
                else
                {
                    // The projectile is waiting on the particles to be destroyed. Stop moving.
                    Stop();
                }
            }
        }