void Update()
    {
        input.x = Input.GetAxis("Move");
        if (input.x > 0 && !facingRight)
        {
            Flip();
        }
        else if (input.x < 0 && facingRight)
        {
            Flip();
        }


        if (Input.GetButton("Jump"))
        {
            input.y = 1;
        }

        if (Input.GetButtonDown("Dash"))
        {
            input.z = 1;
        }

        rend.sprite = currentSprite;

        if (Input.GetButtonDown("Jump") && (groundState.isWall() || groundState.isGround()))
        {
            source.PlayOneShot(clip[0]);
        }
    }
Exemplo n.º 2
0
    void FixedUpdate()
    {
        if (!SonoSuPiattaforma)
        {
            GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0));                                                                       //Move player.
            GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1
        }
        else
        {
            //if(input.x != )
        }

        if (groundState.isWall() && !groundState.isGround() && input.y == 1)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction)
            if (photonView.isMine && PlayerNetwork.possoMorire)
            {
                photonView.RPC("SuonoSalto", PhotonTargets.All);
            }
        }
        if (groundState.isGround() && input.y == 1 && photonView.isMine && PlayerNetwork.possoMorire)
        {
            photonView.RPC("SuonoSalto", PhotonTargets.All);
        }

        anim.SetFloat("Speed", Mathf.Abs(input.x));
        anim.SetBool("IsGrounded", groundState.isGround());
        anim.SetFloat("vSpeed", GetComponent <Rigidbody2D>().velocity.y);

        input.y = 0;
    }
Exemplo n.º 3
0
    string TestPrintState()
    {
        state = "";
        if (groundState.isTouching())
        {
            state += "\n Is Touching a Wall in General.";
        }

        if (groundState.isGround())
        {
            state += "\n Is Touching a Wall on the ground.";
        }
        if (groundState.isWall())
        {
            state += "\n Is Touching a Wall on the side.";
        }
        return(state);
    }
    void FixedUpdate()
    {
        GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0));                                                                       //Move player.
        GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1

        if (groundState.isWall() && !groundState.isGround() && input.y == 1)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction)
        }
        input.y = 0;
    }
Exemplo n.º 5
0
    void FixedUpdate()
    {
        if (!levelController.levelStarted)              //if level hasn't started
        {
            if (inputHorizontal != 0 || inputJumpDown != 0 ||
                inputJumpHeld != 0 || inputDash != 0)
            {
                levelController.LevelStarted();
            }
        }

        if (!levelController.levelCompleted)        //if level hasnt been completed
        {
            //Sprite Rotation
            //Sprite desired rotation based on input
            if (inputHorizontal != 0)
            {
                if (inputHorizontal < 0)
                {
                    charFacingLeft = true;
                }
                else if (inputHorizontal > 0)
                {
                    charFacingLeft = false;
                }
            }
            //Check if a rotation needed
            if (!spriteFacingLeft && charFacingLeft)
            {
                rotationNeeded = true;                                                  //if facing left is false and player is going left a rotation is needed
            }
            else if (spriteFacingLeft && !charFacingLeft)
            {
                rotationNeeded = true;                                                       //if facing left is true and player is going right a rotation is needed
            }
            else
            {
                rotationNeeded = false;             //otherwise the player is rotated the right way
            }
            //if there is a rotation needed
            if (rotationNeeded && charFacingLeft)             //rotate the sprite to the left and update the bool
            {
                transform.localRotation = Quaternion.Euler(0, 0, 0); spriteFacingLeft = true;
            }
            else if (rotationNeeded && !charFacingLeft)             //rotate the sprite to the right and update the bool
            {
                transform.localRotation = Quaternion.Euler(0, 180, 0); spriteFacingLeft = false;
            }

            //Wall Slide Check
            if (!groundState.isGround() && groundState.isWall())
            {
                charWallSliding = true;
            }
            else
            {
                charWallSliding = false;
            }

            //Dashing
            if (groundState.isGround())
            {
                charDashAvailable = true;
            }
            if (!groundState.isGround() && inputDash == 1 && charDashAvailable && !charDashing && charJumpTime >= charDashJumpBufffer)
            //Dash
            {
                animator.SetBool("Dashing", charDashing);               //signal dashing has begun for animator
                charDashing       = true;                               //player is dashing
                charDashAvailable = false;                              //disable the player from dashing again

                if (charWallSliding)
                {                                   //take horizontal direction - if they are wallsliding - perform opposite dash dir
                    if (charFacingLeft && inputHorizontal != -1)
                    {
                        charDashDir = 1;                                                             //if left, dash right
                    }
                    else if (!charFacingLeft && inputHorizontal != 1)
                    {
                        charDashDir = -1;                                                                               //if right dash left
                    }
                }
                else
                {                                               //if not wall sliding
                    if (charFacingLeft)
                    {
                        charDashDir = -1;                                    //if left dash left
                    }
                    else
                    {
                        charDashDir = 1;                                    //if right dash right
                    }
                }

                charJumping         = false;                                //disable the player variable jumping
                charPreDashVelocity = rb.velocity.x;                        //save the players velocity before the dash
                rb.gravityScale     = 0;                                    //disable gravity
                rb.velocity         = new Vector2(charDashDir * charDashSpeed, 0);
            }
            else if (charDashing)             //If the player is in the middle of a dash
            //Continue dashing with dash deceleration until the speed reaches the speed of the player before the dash
            {
                rb.velocity = new Vector2(rb.velocity.x - (charDashDir * charDashDecel), rb.velocity.y);
                if (charDashDir == 1)
                {                                                                                      //dash is to the right
                    if (rb.velocity.x <= charPreDashVelocity || rb.velocity.x <= -charPreDashVelocity) //if the player has slowed to their pre-dash velocity
                    {
                        charDashing = false;
                    }                                                                                   //return the gravity to normal
                }
                else if (charDashDir == -1)
                {                                                                                      //dash is to the left
                    if (rb.velocity.x >= charPreDashVelocity || rb.velocity.x >= -charPreDashVelocity) //if the player has slowed to their pre-dash velocity
                    {
                        charDashing = false;
                    }                                                                                   //return the gravity to normal
                }

                if (!charDashing)
                {
                    charDashing     = false;
                    rb.gravityScale = 2;
                }
            }
            else             //if player has not started a dash or is not dashing
            //Then apply normal movement- walking, jumping etc..
            {
                //reset dash values
                charDashDir         = 0;
                charPreDashVelocity = 0;

                //Walking Movement
                //Move player by the speed value multiplied by ground or air acceleration
                rb.AddForce(new Vector2(((inputHorizontal * charSpeed) - rb.velocity.x) * (groundState.isGround() ? charAccel : charAirAccel), 0));
                //Stop player if input.x is 0 (and grounded)
                rb.velocity = new Vector2((inputHorizontal == 0 && groundState.isGround()) ? 0 : rb.velocity.x, rb.velocity.y);

                //Jumping
                //See if the player has jumped
                if ((charJumpDelayTimer > Time.time || inputJumpDown == 1) && (groundState.isGround() || groundState.isWall()))
                //if jump is pressed for the first time and touching the ground or wall
                {
                    charJumping          = true;                                      //character has started jumping
                    charJumpDurationLeft = charJumpDuration;                          //reset the jump time
                    charJumpDelayTimer   = 0;
                    rb.velocity          = new Vector2(rb.velocity.x, charJumpForce); //make the character jump

                    if (!groundState.isGround())                                      //if player is not touching the ground (wall jump)
                    {
                        charWallDirection = groundState.wallDirection();
                        if (charWallDirection == -1)
                        {
                            charFacingLeft = false;                                                  //left
                        }
                        else if (charWallDirection == 1)
                        {
                            charFacingLeft = true;                                                        //right
                        }
                        rb.velocity = new Vector2(-charWallDirection * charSpeed * 0.75f, rb.velocity.y); //Add force negative to wall direction (with speed reduction)
                        animator.SetTrigger("WallJumped");                                                //signal wall jump for the animator
                    }
                    else
                    {
                        charJumped   = true;
                        charJumpTime = 0;                                           //reset jump time
                        animator.SetTrigger("GroundJumped");                        //signal char jumped to animator (ground jump)
                    }
                }
                else if (inputJumpHeld == 1 && charJumping == true)                         //jump is held and jumping hasnt ended by player letting go of jump
                {
                    //check if jump time hasnt ended yet and the player isnt stuck on ceiling forcing them to have 0 .y velocity
                    if (charJumpDurationLeft > 0 && rb.velocity.y > 0)
                    {
                        rb.velocity           = new Vector2(rb.velocity.x, charJumpForce);              //make the character jump
                        charJumpDurationLeft -= Time.deltaTime;                                         //reduce the jump time
                    }
                }

                if (charJumped)
                {
                    if (charJumpTime >= charDashJumpBufffer)
                    {
                        if (groundState.isGround())
                        {
                            charJumped  = false;
                            rb.velocity = new Vector2(rb.velocity.x, 0);
                        }
                    }
                    charJumpTime += Time.deltaTime;
                }
                else
                {
                    if (!groundState.isGround())
                    {
                        charJumpTime += Time.deltaTime;
                    }
                }

                //if the jumping input stops set jumping to false
                if (inputJumpHeld == 0)
                {
                    charJumping = false;
                }
            }
        }
        else         //level completed
        {
            rb.velocity = new Vector2(0, 0);
        }

        //Animation values
        //send values to the animator
        animator.SetFloat("VelocityY", rb.velocity.y);
        animator.SetBool("WallSliding", charWallSliding);
        animator.SetBool("Dashing", charDashing);

        //check if the input of the horizontal axis is negative
        if (inputHorizontal < 0)
        {
            animator.SetFloat("InputHorizontal", inputHorizontal * -1);                              //send to animator
        }
        else
        {
            animator.SetFloat("InputHorizontal", inputHorizontal);          //otherwise send the positive value
        }
        //check if the velocity of the rb is negative
        if (rb.velocity.x < 0)
        {
            animator.SetFloat("VelocityX", rb.velocity.x * -1);                            //make the velocity positive and send it to the animator
        }
        else
        {
            animator.SetFloat("VelocityX", rb.velocity.x);                  //otherwise send the positive value
        }
        animator.SetBool("Grounded", groundState.isGround());
        if (inputHorizontal == 0 && groundState.isGround())
        {
            stoppedMoving = true;
        }
        else
        {
            stoppedMoving = false;
        }
        animator.SetBool("Stopped", stoppedMoving);

        //Variable Reset
        //resetting input values
        inputHorizontal = 0;
        inputJumpDown   = 0;
        inputJumpHeld   = 0;
        inputDash       = 0;
    }
    void Update()
    {
        if (Team.team.Length == 0)
        {
            return;
        }
        speedTimer -= Time.deltaTime;
        if (speedTimer <= 0)
        {
            speed = 5 + GetComponent <CharacterStats> ().Speed.GetValue();
            if (speed <= 5)
            {
                speed = 10f;
            }
        }
        if (Input.GetKey(KeyBindScript.keys["Up"]))
        {
            rawY = 1f;
        }
        else if (Input.GetKey(KeyBindScript.keys["Down"]))
        {
            rawY = -1f;
        }
        else
        {
            rawY = 0f;
        }

        CharacterStats Character = GetComponent <CharacterStats> ();

        //Handle input
        if (groundState.isTouching() && Input.GetKeyDown(KeyBindScript.keys["Jump"]) && !GetComponent <CharacterStats>().knockBack)
        {
            anim.SetTrigger("takeOf");
            isJumping       = true;
            jumpTimeCounter = jumpTime;
            if (groundState.isTouching())
            {
                createDust();
            }
            input.y = 1;
            audioManager.Play("PlayerJump");
        }
        if (groundState.isGround() == false)
        {
            anim.SetBool("isJumping", true);
        }
        else
        {
            anim.SetBool("isJumping", false);
        }
        if (Input.GetKey(KeyBindScript.keys["Jump"]) && isJumping == true)
        {
            if (jumpTimeCounter > 0)
            {
                // GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 1 * jump);

                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                isJumping = false;
            }
        }
        if (Input.GetKeyUp(KeyBindScript.keys["Jump"]))
        {
            isJumping = false;
        }

        if (Input.GetKey(KeyBindScript.keys["Left"]) && !GetComponent <CharacterStats>().knockBack)
        {
            input.x     = -1;
            lastInput.x = -1;
            if (transform.localRotation.y == 0)
            {
                if (groundState.isGround())
                {
                    createDust();
                }
                if (!isFiring)
                {
                    transform.localRotation = Quaternion.Euler(0, 180, 0);
                    facing = -1;
                }
            }
            if (!isJumping)
            {
                anim.SetBool("isRunning", true);
            }
        }
        else if (Input.GetKey(KeyBindScript.keys["Right"]) && !GetComponent <CharacterStats>().knockBack)
        {
            input.x     = 1;
            lastInput.x = 1;
            if (transform.localRotation.y == -1)
            {
                if (groundState.isGround())
                {
                    createDust();
                }
                if (!isFiring)
                {
                    transform.localRotation = Quaternion.Euler(0, 0, 0);
                    facing = 1;
                }
            }
            if (!isJumping)
            {
                anim.SetBool("isRunning", true);
            }
        }
        else
        {
            input.x = 0;
            anim.SetBool("isRunning", false);
        }
        if (isJumping)
        {
            anim.SetBool("isRunning", false);
        }
        if (isJumping && groundState.isGround())
        {
            isJumping = false;
        }
        if (GetComponent <Rigidbody2D> ().velocity.y < 0 && groundState.isTouching() == false)
        {
            jumped = true;
        }
        if (groundState.isWall() && !groundState.isGround())
        {
            anim.SetBool("isWall", true);
            createDust();
        }
        else
        {
            anim.SetBool("isWall", false);
        }
        // Fire
        if (Character.currentAffliction != "Pacifist")
        {
            if (Input.GetKey(KeyBindScript.keys["Fire"]) && Time.time > nextFire)
            {
                nextFire = Time.time + Team.team[GetComponent <CharacterStats> ().currentChar].fireRate;
                fire();
                // shake.camShake();
            }
            if (Input.GetKeyDown(KeyBindScript.keys["Fire"]))
            {
                isFiring = true;
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Fire"]))
            {
                isFiring = false;
            }
        }
        // Mechanic
        if (Character.ClassType.GetValue() == 1)          // Runner
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && canDash && Time.time > nextDash)
            {
                audioManager.Play("Runner", UnityEngine.Random.Range(1, 3));
                Dash(input.x, rawY);
                Team.team[Character.currentChar].runner_state = 0;
                nextDash = Time.time + Character.runner_CDR;
            }
            else if (Time.time > nextRefreshRunner)
            {
                nextRefreshRunner = Time.time + 0.1f;
                if (Team.team[Character.currentChar].runner_state + Team.team[Character.currentChar].runner_step > 20)
                {
                    Team.team[Character.currentChar].runner_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].runner_state += Team.team[Character.currentChar].runner_step;
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 2)            //Climber
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && Time.time > nextClimb)
            {
                //create the link (raycast ...)
                audioManager.Play("Climber", UnityEngine.Random.Range(1, 3));

                int          LayerIndex = LayerMask.NameToLayer("Ground");
                int          layerMask  = (1 << LayerIndex);
                RaycastHit2D hit;

                hit                   = Physics2D.Raycast(transform.position, new Vector2(facing < 0 ? -0.5f : 0.5f, 1), Mathf.Infinity, layerMask);
                joint.enabled         = true;
                joint.connectedBody   = hit.collider.gameObject.GetComponent <Rigidbody2D> ();
                joint.connectedAnchor = hit.point - new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.y);
                joint.distance        = Vector2.Distance(transform.position, hit.point);
                line.enabled          = true;
                line.SetPosition(0, transform.position);
                line.SetPosition(1, hit.point);
                nextClimb = Time.time + Character.climber_CDR;
                if (Team.team[Character.currentChar].climber_state == 20)
                {
                    Team.team[Character.currentChar].climber_state = 0;
                }
            }
            else if (Time.time > nextRefreshClimber)
            {
                nextRefreshClimber = Time.time + 0.1f;
                if (Team.team[Character.currentChar].climber_state + Team.team[Character.currentChar].climber_step > 20)
                {
                    Team.team[Character.currentChar].climber_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].climber_state += Team.team[Character.currentChar].climber_step;
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                if (joint.distance > 0.2f)
                {
                    joint.distance -= step;
                }
                else
                {
                    joint.enabled = false;
                    line.enabled  = false;
                }
                line.SetPosition(0, transform.position);
            }
            else if (Time.time > nextRefreshClimber)
            {
                nextRefreshClimber = Time.time + 0.1f;
                if (Team.team[Character.currentChar].climber_state + Team.team[Character.currentChar].climber_step > 20)
                {
                    Team.team[Character.currentChar].climber_state = 20;
                }
                else
                {
                    Team.team[Character.currentChar].climber_state += Team.team[Character.currentChar].climber_step;
                }
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
                // delete the link

                joint.enabled = false;
                line.enabled  = false;
            }
        }
        else if (Character.ClassType.GetValue() == 3)            // Hacker
        {
            GameObject[] turrets = GameObject.FindGameObjectsWithTag("Turret");
            GameObject   turret  = GetClosestTurret(turrets);
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                audioManager.Play("Hacker", UnityEngine.Random.Range(1, 3));
                // Show range
                foreach (GameObject n in turrets)
                {
                    if (!n.transform.GetChild(1).gameObject.GetComponent <turretScript> ().getDeactivation())
                    {
                        n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = true;
                    }
                    else
                    {
                        n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = false;
                    }
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                if (turret)
                {
                    turret.transform.GetChild(1).gameObject.GetComponent <turretScript> ().hack(transform.position);
                }
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
                // Hide range
                foreach (GameObject n in turrets)
                {
                    n.transform.GetChild(3).GetComponent <SpriteRenderer> ().enabled = false;
                    n.transform.GetChild(1).gameObject.GetComponent <turretScript> ().resetHack();
                }
            }
        }
        else if (Character.ClassType.GetValue() == 4)            // Tracker
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]) && Time.time > NextFlag && groundState.isGround() && Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags > 0)
            {
                audioManager.Play("Tracker", UnityEngine.Random.Range(1, 3));
                NextFlag = Time.time + FlagRate;
                Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags -= 1;
                GetComponent <CharacterStats> ().UpdatePower();
                // Spawn a landmark
                Instantiate(FlagSprite, new Vector3(transform.position.x, transform.position.y - 0.1f, transform.position.z), Quaternion.identity);
            }
            else if (Team.team[GetComponent <CharacterStats> ().currentChar].nbFlags <= 0)
            {
                // display error msg for 2 sec
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 5)            // Tank
        {
            if (Shield.activeSelf == true)
            {
                Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield += Time.deltaTime;
                Team.team[GetComponent <CharacterStats> ().currentChar].tank_state        = (int)(Team.team[GetComponent <CharacterStats> ().currentChar].tank_shield - Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield);
                GetComponent <CharacterStats> ().UpdatePower();
            }
            if (Team.team[GetComponent <CharacterStats> ().currentChar].used_tank_shield >= Character.tank_shield)
            {
                canShield = false;
                Shield.SetActive(false);
            }
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                audioManager.Play("Tank", UnityEngine.Random.Range(1, 3));
                if (Shield.activeSelf == false && canShield)
                {
                    Shield.SetActive(true);
                }
                else
                {
                    Shield.SetActive(false);
                }
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
        else if (Character.ClassType.GetValue() == 6)            // Grenadier
        {
            if (Input.GetKeyDown(KeyBindScript.keys["Action"]))
            {
                shootBomb();
            }
            if (Input.GetKey(KeyBindScript.keys["Action"]))
            {
                shootBomb();
            }
            if (Input.GetKeyUp(KeyBindScript.keys["Action"]))
            {
            }
        }
    }
Exemplo n.º 7
0
    void FixedUpdate()
    {
        if (path == null)
        {
            return;
        }
        if (currentWaypoint >= path.vectorPath.Count)
        {
            reachedEndOfPath = true;
            return;
        }
        else
        {
            reachedEndOfPath = false;
        }

        if (Vector2.Distance(transform.position, target.position) > 4f && transform.position.x != target.position.x)
        {
            Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rb.position).normalized;
            Vector2 force     = direction * speed * Time.deltaTime;

            Vector2 velocity = rb.velocity;
            velocity.x  = force.x;
            rb.velocity = velocity;

            if (force.x > 0)
            {
                transform.localRotation = Quaternion.Euler(0, 0, 0);
            }
            else if (force.x < 0)
            {
                transform.localRotation = Quaternion.Euler(0, 180, 0);
            }

            if (direction.y > 0.5 && groundState.isGround())
            {
                rb.velocity = new Vector2(rb.velocity.x, 1 * jumpspeed);
            }
            else if (direction.y > 0.01 && groundState.isWall())
            {
                rb.velocity = new Vector2(rb.velocity.x, jumpspeed); //Add force negative to wall direction (with speed reduction)
            }
            else if (direction.y < 0 && !groundState.isGround())
            {
                rb.velocity = new Vector2(0, -jumpspeed); //Add force negative to wall direction (with speed reduction)
            }
            else
            {
                rb.velocity = new Vector2(force.x, rb.velocity.y);
            }
        }
        else
        {
            // fire
            if (Time.time > nextFire)
            {
                nextFire = Time.time + FireRate;
                StartCoroutine(Shoot());
            }
        }

        // if (force.y > 0)
        // {
        //     velocity.y = force.y;
        //     rb.velocity = velocity;
        // }


        float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]);

        if (distance < nextWaypointDistance)
        {
            currentWaypoint++;
        }
    }