Ejemplo n.º 1
0
    public override void Use(Transform user)
    {
        base.Use(user);

        BulletPool bPool = BulletPool.bullets;

        bPool.Fire(user);
    }
Ejemplo n.º 2
0
    void LateUpdate()
    {
        Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;

        rb.AddForce(direction * speed * Time.fixedDeltaTime, ForceMode.VelocityChange);
        animator.SetFloat("speed", rb.velocity.magnitude);
        if (enemyList.Count > 0)
        {
            //Find left and right cloesest enemies
            Enemy leftClosestEnemy  = GetClosestEnemy(enemyList, leftEnemySearcher);
            Enemy rightClosestEnemy = GetClosestEnemy(enemyList, rightEnemySearcher);
            float distanceLeft      = (leftClosestEnemy.transform.position - leftWrist.transform.position).magnitude;
            float distanceRight     = (rightClosestEnemy.transform.position - rightWrist.transform.position).magnitude;

            ////Override Arm Animation
            leftForeArm.transform.localRotation   = Quaternion.Euler(new Vector3(0f, 15f, -55f));
            rightForeArm.transform.localRotation  = Quaternion.Euler(new Vector3(110f, -35f, -50f));
            upperLeftArm.transform.localRotation  = Quaternion.Euler(new Vector3(10f, 7f, 49f));
            upperRightArm.transform.localRotation = Quaternion.Euler(new Vector3(-2f, -7f, 49f));
            leftWrist.transform.localRotation     = Quaternion.Euler(new Vector3(0f, 0f, 55f));
            rightWrist.transform.localRotation    = Quaternion.Euler(new Vector3(-90f, -90f, 85f));


            if ((distanceLeft <= gameManager.PlayerAttackRange || distanceRight <= gameManager.PlayerAttackRange) && !animator.GetBool("isForceShield"))
            {
                //Rotate towards to enemy

                Vector3    leftEnemyDirection    = (leftClosestEnemy.transform.position - transform.position).normalized;                                             //Enemy to Player
                Quaternion lookLeftRotationEnemy = Quaternion.LookRotation(leftEnemyDirection, Vector3.up);
                float      playerYLeftTransform  = Quaternion.RotateTowards(lookLeftRotationEnemy, transform.rotation, rotationSpeed * Time.deltaTime).eulerAngles.y; //Player Y transform value needded to look towards enemy
                bool       isLeftTargetable      = CheckTargetable(playerYLeftTransform, Targetable.LeftTargetable);

                Vector3    rightEnemyDirection    = (rightClosestEnemy.transform.position - transform.position).normalized;                                             //Enemy to Player
                Quaternion lookRightRotationEnemy = Quaternion.LookRotation(rightEnemyDirection, Vector3.up);
                float      playerYRightTransform  = Quaternion.RotateTowards(lookRightRotationEnemy, transform.rotation, rotationSpeed * Time.deltaTime).eulerAngles.y; //Player Y transform value needded to look towards enemy
                bool       isRightTargetable      = CheckTargetable(playerYRightTransform, Targetable.RightTargetable);

                if (isLeftTargetable && isRightTargetable)  // both arms can shoot different enemies
                {
                    float leftArmZRotation  = YZRotationMapper(playerYLeftTransform);
                    float rightArmZRotation = YZRotationMapper(playerYRightTransform);

                    leftArm.transform.localRotation  = Quaternion.Euler(new Vector3(-165f, 90f, leftArmZRotation));
                    rightArm.transform.localRotation = Quaternion.Euler(new Vector3(15f, 90f, rightArmZRotation));
                }
                else // only enemy from left or right can be shoot bcs robot can open arms up to some degree, shoot closest
                {
                    Enemy closestEnemy;
                    if (distanceLeft < distanceRight)
                    {
                        closestEnemy = leftClosestEnemy;
                    }
                    else
                    {
                        closestEnemy = rightClosestEnemy;
                    }

                    Vector3    enemyDirection    = (closestEnemy.transform.position - transform.position).normalized;
                    Quaternion lookRotationEnemy = Quaternion.LookRotation(enemyDirection, Vector3.up);
                    transform.rotation = Quaternion.Euler(new Vector3(0f, Quaternion.RotateTowards(lookRotationEnemy, transform.rotation, rotationSpeed * Time.fixedDeltaTime).eulerAngles.y));
                    leftArm.transform.localRotation  = Quaternion.Euler(new Vector3(-165f, 90f, 39f));
                    rightArm.transform.localRotation = Quaternion.Euler(new Vector3(15f, 90f, 39f));
                }
                fireTimer += Time.fixedDeltaTime;
                //Start fire
                if (fireTimer >= gameManager.FireRate)
                {
                    fireTimer = 0;
                    GameObject leftBullet  = pool.Fire(currentBulletType, fireStarterLeft.transform.position, leftGun.transform.rotation);
                    GameObject rightBullet = pool.Fire(currentBulletType, fireStarterRigth.transform.position, rightGun.transform.rotation);
                }
            }
            else //normal movement
            {
                //Rotate with joystick
                Vector3 directionJoystick = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
                if (directionJoystick != Vector3.zero)
                {
                    Vector3    lookDirection = new Vector3(variableJoystick.Horizontal, 0, variableJoystick.Vertical);
                    Quaternion lookRotation  = Quaternion.LookRotation(lookDirection, Vector3.up);

                    float step = rotationSpeed * Time.deltaTime;
                    transform.rotation = Quaternion.RotateTowards(lookRotation, transform.rotation, step);
                }
            }
        }
    }