Ejemplo n.º 1
0
 public void OnMeleeHit(Collider2D other)
 {
     F3DGenericProjectile.DealDamage(transform.root.gameObject, DamageType, DamageAmount, Type, other.transform, BarrelSpark, 1f,
                                     other.bounds.ClosestPoint(FXSocket.position), FXSocket.up);
 }
Ejemplo n.º 2
0
    protected void SpawnProjectile(Transform projectilePrefab)
    {
        // Direction
        _dir = Mathf.Sign(FXSocket.parent.lossyScale.x);

        // Run close distance check from the bone pivot to the FXSocket twice long

        //
        Debug.DrawLine(FXSocket.position - FXSocket.right * _dir,
                       FXSocket.position + FXSocket.right * 2 * _dir, Color.red, 0.5f);

        //
        var closeCheckHit = Physics2D.LinecastAll(FXSocket.position - FXSocket.right * _dir,
                                                  FXSocket.position + FXSocket.right * ProjectileCloseRange * _dir, ProjectileHitLayerMask);

        // Close range hit - Spawn the impact and play hit sound without spawning the projectile
        if (closeCheckHit != null && closeCheckHit.Length > 0)
        {
            var projObject = projectilePrefab.GetComponent <F3DGenericProjectile>();

            // Ignore own colliders
            for (var i = 0; i < closeCheckHit.Length; i++)
            {
                var selfHit = false;
                for (var j = 0; j < _colliders.Length; j++)
                {
                    if (closeCheckHit[i].collider == _colliders[j])
                    {
                        selfHit = true;
                        break;
                    }
                }
                if (selfHit)
                {
                    continue;
                }

                F3DGenericProjectile.DealDamage(transform.root.gameObject, DamageType, DamageAmount, Type, closeCheckHit[i].transform, projObject.Hit,
                                                projObject.HitLifeTime,
                                                closeCheckHit[i].point, closeCheckHit[i].normal);
                // Play close impact through the attached soundSource
                F3DWeaponAudio.OnProjectileImpact(_weaponAudio.ProjectileHitClose, AudioInfo);
                return;
            }
        }

        // Keep the initial position, rotaion of the FXSocket so the projectile is launched in the correct _dir
        // Random Offset

        // Position
        var position = FXSocket.position + FXSocket.right * ProjectileOffset.x * _dir;

        position.z = 0;

        // Rotation
        var rotation = FXSocket.rotation;

        if (_dir < 0)
        {
            rotation *= Quaternion.Euler(0, 0, 180);
        }
        rotation *= Quaternion.Euler(0, 0, Random.Range(ProjectileRotation.x, ProjectileRotation.y));

        // Spawn Delayed
        StartCoroutine(SpawnProjectileDelayed(projectilePrefab, position, rotation));
    }