예제 #1
0
    //
    void UpdateCanonRotation(Vector3 playerDirection, float dt)
    {
        // TODO: Mirar como hacer fuego indirecto
        // Mirar angulo, si por debajo de 45
        // Debería haber otro por encima válido
        Vector3 anticipatedPlayerPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            shootPoint.position, player.transform.position, playerRB.velocity, muzzleSpeed, dt);

        // Gravity
        anticipatedPlayerPosition.y -= GeneralFunctions.GetProyectileFallToObjective(shootPoint.position, anticipatedPlayerPosition, muzzleSpeed);

        // And check if direct or indirect fire
        if (typeOfFire == TypeOfFire.Indirect)
        {
            Vector3 playerDirNormalized = anticipatedPlayerPosition.normalized;
            float   angle = Mathf.Acos(playerDirNormalized.y) * Mathf.Rad2Deg;
            angle = 90 - angle;
            playerDirNormalized.y = Mathf.Cos(angle);
        }

        // Rotamos
        if (doesRotate)
        {
            //
            transform.rotation = GeneralFunctions.UpdateRotation(transform, anticipatedPlayerPosition, rotationSpeed.x, dt);
            // TODO: Hacerlo en general functions
            if (rotationIsConstrained)
            {
                ConstrainRotation();
            }
            // Y anulamos rotación en z (si no los bichos se esnucan)
            transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, 0);
        }
    }
예제 #2
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);
        }
    }
예제 #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="dt"></param>
    void RapidFireAttack(float dt)
    {
        //
        //rapidFireCooldown += dt;
        //
        if (/*rapidFireCooldown*/ chargedAmount >= 1 / gameManager.playerAttributes.rapidFireRate.CurrentValue)
        {
            // La calculamos desde los puntos de la ametralladora para más precision
            // TODO: Revisar aqui tambien el cambio de centralPointOffset
            if (EnemyAnalyzer.isActive)
            {
                EnemyAnalyzer.estimatedToHitPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
                    machineGunPoints[nextRapidFireSide].position,
                    EnemyAnalyzer.enemyTransform.position,
                    //EnemyAnalyzer.enemyTransform.TransformPoint(EnemyAnalyzer.enemyConsistency.centralPointOffset),
                    EnemyAnalyzer.enemyRb.velocity,
                    currentMuzzleSpeed, dt);
            }

            //
            float bulletDrag = proyectileRb.drag;
            EnemyAnalyzer.estimatedToHitPosition.y += GeneralFunctions.GetProyectileFallToObjective(transform.position,
                                                                                                    EnemyAnalyzer.estimatedToHitPosition, currentMuzzleSpeed, bulletDrag) * 1;

            //
            //Vector3 shootForward = (!cameraControl.TargetingPlayer) ?
            //    (EnemyAnalyzer.estimatedToHitPosition - machineGunPoints[nextRapidFireSide].position).normalized :
            //    machineGunPoints[nextRapidFireSide].forward;

            //
            Vector3 targetPoint;
            if (EnemyAnalyzer.isActive)
            {
                targetPoint = EnemyAnalyzer.estimatedToHitPosition;
                //
                Quaternion shootRotation = Quaternion.LookRotation(targetPoint - machineGunPoints[nextRapidFireSide].position);
                machineGunPoints[nextRapidFireSide].rotation = shootRotation;
            }
            else
            {
                //targetPoint = cameraControl.CurrentTarget.position;
                machineGunPoints[nextRapidFireSide].rotation = transform.rotation;
            }

            //
            CharguedProyectileAttack(proyectileToUse, machineGunPoints[nextRapidFireSide], dt);

            //
            //chargedAmount = 0.01f;
            //rapidFireCooldown -= 1 / gameManager.playerAttributes.rapidFireRate;
            chargedAmount = 0.01f;
            //
            nextRapidFireSide = (nextRapidFireSide) == 0 ? 1 : 0;
            //
            GeneralFunctions.PlaySoundEffect(audioSource, rapidFireClip, 0.1f);
        }
    }
예제 #4
0
    void UpdateTurretRotation(Vector3 playerDirection, float dt)
    {
        //
        //transform.rotation = GeneralFunctions.UpdateRotation(transform, player.transform.position, turretRotationSpeed, dt);
        Vector3 anticipatedPlayerPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            transform.position, player.transform.position, playerRB.velocity, weapons[0].muzzleSpeed, dt);

        //transform.rotation = GeneralFunctions.UpdateRotation(transform, anticipatedPlayerPosition, turretRotationSpeed, dt);
        transform.rotation = GeneralFunctions.UpdateRotationInOneAxis(transform, anticipatedPlayerPosition, turretRotationSpeed, dt);
    }
예제 #5
0
    private void ThrowBodies(float dt)
    {
        // Si no ha atrapado ningún objeto pasamos
        if (liftedObjects.Count == 0)
        {
            return;
        }
        //
        float desiredProyectileSpeed = 500;
        //
        Vector3 playerStimatedPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            liftedObjects[0].liftedRb.position,
            player.transform.position,
            PlayerReference.playerRb.velocity, desiredProyectileSpeed, dt);

        //
        playerStimatedPosition.y += GeneralFunctions.GetProyectileFallToObjective(liftedObjects[0].liftedRb.position,
                                                                                  player.transform.position, desiredProyectileSpeed);
        //
        Vector3 playerStimatedDirection = player.transform.position - liftedObjects[0].liftedRb.position;

        // Inital approach
        for (int i = 0; i < liftedObjects.Count; i++)
        {
            //
            //Vector3 playerStimatedPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            //    liftedObjects[i].liftedRb.position,
            //    player.transform.position,
            //    PlayerReference.playerRb.velocity, desiredProyectileSpeed, dt);
            //playerStimatedPosition.y += GeneralFunctions.GetProyectileFallToObjective(liftedObjects[i].liftedRb.position,
            //    player.transform.position, desiredProyectileSpeed);
            ////
            //Vector3 playerStimatedDirection = player.transform.position - liftedObjects[i].liftedRb.position;

            // TODO: HAcer que Carol o el bullet pool pinte las trayectorias
            if (i < liftedObjectsTrails.Count)
            {
                AllocateTrayectoryLineRenderer(liftedObjects[i].liftedRb, liftedObjectsTrails[i],
                                               playerStimatedDirection.normalized * desiredProyectileSpeed);
            }
            else
            {
                Debug.Log("More bodies than expected");
            }
            // De momento le asignamos la velicdad a palo seco
            //liftedObjects[i].liftedRb.AddForce(playerStimatedDirection.normalized * desiredProyectileSpeed, ForceMode.VelocityChange);
            liftedObjects[i].liftedRb.velocity = playerStimatedDirection.normalized * desiredProyectileSpeed;
            //
            carolHelp.TriggerGeneralAdvice("GreatDangerIncoming");
        }
    }
예제 #6
0
    // TODO: Hacer que la cámara se enfoque en el punto que va a ocupar el enemigo
    // En proporcion a la velocidad del proyectil actual
    // Será aqui donde trabajemos el fijado
    void AdjustToEnemyMovement(float dt)
    {
        //
        if (!EnemyAnalyzer.isActive)
        {
            return;
        }
        // TODO: Crear metodo más felxible
        // Trabajar no solo con enemy consistency

        /*if(EnemyAnalyzer.enemyConsistency == null)
         * {
         *  EnemyAnalyzer.Release();
         *  return;
         * }*/

        // TODO: Hemos movido el centralPointOffset a Targeteable
        // Empezamos cogiendo la posición del enemigo
        //Vector3 targetPoint = EnemyAnalyzer.enemyTransform.TransformPoint(EnemyAnalyzer.enemyConsistency.centralPointOffset);
        Vector3 targetPoint = EnemyAnalyzer.enemyTransform.position;

        // TODO: Sacar un índice del arma actualmente equipada para usar su muzzle speed en la función de atnicpar
        Rigidbody enemyRigidbody = EnemyAnalyzer.enemyRb;

        // Determinamos donde va a estar cuando el proyectil llegue a él
        //
        float proyectileMuzzleSpeed = 1000;

        proyectileMuzzleSpeed = PlayerReference.playerControl.CurrentMuzzleSpeed;

        //
        float dragToCheck = (PlayerReference.currentProyectileRB != null) ? PlayerReference.currentProyectileRB.drag : 0.1f;

        //
        EnemyAnalyzer.estimatedToHitPosition = GeneralFunctions.AnticipateObjectivePositionForAiming(
            transform.position, targetPoint, enemyRigidbody.velocity, proyectileMuzzleSpeed, dt,
            dragToCheck);
        // Determinamos el
        // TODO: Coger el punto de disparo del plauer
        EnemyAnalyzer.estimatedToHitPosition.y += GeneralFunctions.GetProyectileFallToObjective(transform.position,
                                                                                                EnemyAnalyzer.estimatedToHitPosition, proyectileMuzzleSpeed);
        //
        targetPos = EnemyAnalyzer.estimatedToHitPosition;
    }