コード例 #1
0
    protected void FireFormationWeapon(float dt)
    {
        GameObject nextBullet =
            BulletPool.instance.GetBullet(formationWeaponData.weapon.proyectilePrefab, enemyFormation.FormationStrength);
        //Debug.Log(nextBullet);
        //
        Vector3 attackPosition = transform.TransformPoint(enemyFormation.formationInfo.attackPosition);
        //
        Vector3 anticipatedPlayerPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            attackPosition, player.transform.position, PlayerReference.playerRb.velocity,
            formationWeaponData.weapon.muzzleSpeed, dt);

        // Gravity
        anticipatedPlayerPosition.y -= GeneralFunctions.GetProyectileFallToObjective(attackPosition, anticipatedPlayerPosition,
                                                                                     formationWeaponData.weapon.muzzleSpeed);


        Vector3 attackDirection = anticipatedPlayerPosition - attackPosition;

        //
        GeneralFunctions.ShootProjectileFromPool(nextBullet, attackPosition,
                                                 Quaternion.LookRotation(attackDirection), attackDirection.normalized, formationWeaponData.weapon.muzzleSpeed, dt, ShootCalculation.MuzzleSpeed);
        //
        Missile missile = nextBullet.GetComponent <Missile>();

        if (missile && missile.seeksObjective)
        {
            missile.AssignObjective(player.transform);
        }
    }
コード例 #2
0
    //
    public void Shoot(float dt)
    {
        //Debug.Log(shootPoint);
        GameObject proyectileToUse = bulletPool.GetBullet(proyectilePrefab);

        if (!proyectileToUse)
        {
            return;
        }
        // TODO: Incluir shootCalculation
        //GameObject newProyectile = GeneralFunctions.ShootProjectile(proyectilePrefab, shootPoint.position,
        //    shootPoint.rotation, shootPoint.forward, muzzleSpeed, dt, ShootCalculation.MuzzleSpeed);
        GeneralFunctions.ShootProjectileFromPool(proyectileToUse, shootPoint.position,
                                                 shootPoint.rotation, shootPoint.forward, muzzleSpeed, dt, ShootCalculation.MuzzleSpeed);
        //
        if (shootParticlesPrefab != null)
        {
            Instantiate(shootParticlesPrefab, shootPoint.position, Quaternion.identity);
        }
        //
        Missile missile = proyectileToUse.GetComponent <Missile>();

        if (missile != null)
        {
            missile.AssignObjective(player.transform);
            Debug.Log(player.transform);
        }


        //
        //if (!enemyManager.IsFiringClipActive(shootingClip))
        //{
        //    enemyManager.AddClip(shootingClip);
        GeneralFunctions.PlaySoundEffectWithoutOverlaping(audioSource, shootingClip);
        //}

        // TODO: Revisar por qué sale tan gore
        Rigidbody proyectileRb = proyectileToUse.GetComponent <Rigidbody>();
        float     lauchForce   = proyectileRb.velocity.magnitude * proyectileRb.mass;

        bodyRb.AddForce(-transform.forward * lauchForce);
    }