Exemple #1
0
    protected virtual void OnCollisionEnter(Collision collision)
    {
        //Debug.Log("[" + this.GetType().ToString() + "] hit");

        if (isServer)
        {
            var hit        = collision.gameObject;
            var damageable = hit.gameObject.GetComponentInParent <Damageable>();

            if (damageable)
            {
                if (!isClient)
                {
                    OnProjectileHit.Invoke();
                }

                RpcProjectileHit();

                damageable.Hit(profile.damage, gameObject, collision);
            }

            if (DestroyedOnImpact)
            {
                DestroyProjectile();
            }

            HapticCollisionTrigger trigger = collision.collider.gameObject.GetComponent(typeof(HapticCollisionTrigger)) as HapticCollisionTrigger;
            if (trigger && collision.contacts.Length > 0)
            {
                trigger.TriggerHaptic(collision.contacts[0].point);
            }
        }
        else
        {
            if (DestroyedOnImpact)
            {
                OnProjectileDestroyed.Invoke();
            }
        }
    }
Exemple #2
0
    protected void RaycastBullet(Projectile bullet, RaycastHit hit)
    {
        if (isServer)
        {
            cooldownTimer = m_fireRate;
            FiredCount   += 1;

            if (m_magazineSize > -1)
            {
                shotsRemaining -= 1;
            }

            if (burstCount == 0)
            {
                OnBurstStart.Invoke();
                RpcBurst(false);
            }
        }

        OnBulletFired.Invoke();

        // Simulate projectile hit
        if (hit.collider)
        {
            if (hit.rigidbody)
            {
                Vector3 bulletTrajectory = (hit.point - ProjectileSpawnPoint.position).normalized;
                Vector3 bulletVelocity   = FireForce * bullet.projectileBody.mass * bulletTrajectory;
                //float bulletIncidence = Vector3.Dot(bulletVelocity, -hit.normal);

                hit.rigidbody.AddForceAtPosition(bulletVelocity, hit.point, ForceMode.Impulse);
                // hit.rigidbody.AddTorque(bulletVelocity * (1 - bulletIncidence), ForceMode.Impulse);
            }

            if (isServer)
            {
                var bulletCollider    = bullet.gameObject.GetComponent <Collider>();
                var bulletEffectLayer = bullet.gameObject.GetComponent <DirectorEventCollision>();

                if (collisionParticleEffects.instance != null)
                {
                    collisionParticleEffects.instance.playParticles(this.GetInstanceID(), bulletCollider, hit.collider, hit.point, hit.normal);
                }

                if (sfxManager.instance != null)
                {
                    sfxManager.instance.playCollisionSfx(bulletCollider, hit.collider, hit.point);
                }

                if (Spaces.LBE.EventManager.instance != null && bulletEffectLayer)
                {
                    effectsLayers otherLayers = hit.collider.GetComponent <effectsLayers>();

                    if (otherLayers != null)
                    {
                        if (FXLayers.isMatch(bulletEffectLayer.m_AudioLayer.value, otherLayers.m_AudioLayer.value) ||
                            FXLayers.isMatch(bulletEffectLayer.m_ParticlesLayer.value, otherLayers.m_ParticlesLayer.value))
                        {
                            // FENG_TODO: Will replace the previous EventManager with SpacesEventManager. Now just handle the waterTowerHit first
                            if (bulletEffectLayer.m_CollisionEvent == Spaces.LBE.SpEvent.EventType.WaterTowerHit)
                            {
                                Spaces.LBE.SpacesEventManager.TriggerEvent(Spaces.LBE.SpacesEventType.Mister, null);
                            }
                            else
                            {
                                Spaces.LBE.EventManager.instance.SendEvent(new Spaces.LBE.SpEvent(bulletEffectLayer.m_CollisionEvent));
                            }
                        }
                    }
                }

                HapticCollisionTrigger hTrigger = hit.collider.GetComponent <HapticCollisionTrigger>();
                if (hTrigger)
                {
                    hTrigger.TriggerHaptic(hit.point);
                }
            }
        }
    }