Ejemplo n.º 1
0
    void Update()
    {
        h  = leftJoystick.GetInputDirection().x;
        v  = leftJoystick.GetInputDirection().y;
        rH = rightJoystick.GetInputDirection().x;
        rV = rightJoystick.GetInputDirection().y;

        cameraForward = mainCamera.transform.forward;
        cameraRight   = mainCamera.transform.right;

        cameraForward.Normalize();

        if (chara.isGrounded)
        {
            moveDirection = (h * cameraRight + v * cameraForward) * speed;
        }

        lookDirection = (rH * cameraRight + rV * cameraForward) * speed;

        if (rH != 0 || rV != 0)
        {
            //transform.Rotate(-Vector3.up * turnSpeed * Time.deltaTime);
            Quaternion rotate = Quaternion.LookRotation(lookDirection);
            rotate.x = 0;
            rotate.z = 0;

            transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * turnSpeed);
        }

        moveDirection.x *= 2;
        moveDirection.y  = 0;
        moveDirection.y -= gravity * Time.deltaTime;
        chara.Move(moveDirection * Time.deltaTime);

        if (isInvicible)
        {
            invicibleCooldown += Time.deltaTime;
            if (invicibleCooldown >= invicibleTime)
            {
                isInvicible = false;
            }
        }

        if (canShoot)
        {
            Shoot();
        }
        else
        {
            shootCooldown += Time.deltaTime;
            if (shootCooldown >= shootFreq)
            {
                canShoot = true;
            }
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (CameraFollowObj == null)
        {
            if (startedDestory == false)
            {
                startedDestory = true;
                Destroy(gameObject, 4);
            }
        }
        transform.position = CameraFollowObj.transform.position;
        transform.rotation = CameraFollowObj.transform.rotation;
        if (mobileSupport)
        {
            yaw   += 160 * RJ.GetInputDirection().x *Time.deltaTime;
            pitch -= 120 * RJ.GetInputDirection().y *Time.deltaTime;
        }
        else
        {
            if (Input.GetKey(KeyCode.Mouse1))
            {
                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;

                yaw   += 190 * Input.GetAxisRaw("Mouse X") * Time.deltaTime;
                pitch -= 150 * Input.GetAxis("Mouse Y") * Time.deltaTime;
            }
            else
            {
                Cursor.lockState = CursorLockMode.None;
                Cursor.visible   = true;
            }
        }
        if (pitch > 40)
        {
            pitch = 40;
        }
        else if (pitch < -30)
        {
            pitch = -30;
        }
        transform.eulerAngles = new Vector3(pitch, yaw, 0);
        print(transform.eulerAngles.z);

        /* if (transform.eulerAngles.x > 40)
         * {
         *   transform.eulerAngles = new Vector3(40, transform.eulerAngles.y, 0);
         * }
         * else if (transform.eulerAngles.x < 330 && transform.eulerAngles.x > 180)
         * {
         *   transform.eulerAngles = new Vector3(330, transform.eulerAngles.y, 0);
         * }*/
        ElectronCountText.text = CameraFollowObj.transform.root.GetComponent <PlayerController>().EM.countOfCurrentElectrons.ToString();
    }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        // get input from joystick
        rightJoystickInput = rightJoystick.GetInputDirection();

        float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 02
        float zMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 02

        // if there is no input on the right joystick
        if (rightJoystickInput == Vector3.zero)
        {
            animator.SetBool("isAttacking", false);
        }

        // if there is only input from the right joystick
        if (rightJoystickInput != Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngle = Mathf.Atan2(zMovementRightJoystick, xMovementRightJoystick);
            xMovementRightJoystick *= Mathf.Abs(Mathf.Cos(tempAngle));
            zMovementRightJoystick *= Mathf.Abs(Mathf.Sin(tempAngle));

            // rotate the player to face the direction of input
            Vector3 temp = transform.position;
            temp.x += xMovementRightJoystick;
            temp.z += zMovementRightJoystick;
            Vector3 lookDirection = temp - transform.position;
            if (lookDirection != Vector3.zero)
            {
                rotationTarget.localRotation = Quaternion.Slerp(rotationTarget.localRotation, Quaternion.LookRotation(lookDirection) * Quaternion.Euler(0, 45f, 0), rotationSpeed * Time.deltaTime);
            }

            animator.SetBool("isAttacking", true);
        }
    }
Ejemplo n.º 4
0
    public void RotatingControllerUpdate()
    {
        Vector2 p = rightJoyStick.GetInputDirection();

        if ((p.x > -0.2f && p.x < 0.2) && (p.y > -0.2f && p.y < 0.2))
        {
            return;
        }

        float angle = Mathf.Atan(p.y / p.x) * Mathf.Rad2Deg;

        if (p.x < 0)
        {
            if (p.y < 0)
            {
                angle -= 180;
            }
            else
            {
                angle += 180;
            }
        }
        //playerController.Shoot();

        //Debug.Log("Angle : " + angle + " sw : " + Screen.width + " mw : " + Input.mousePosition.x);
        playerController.Rotate(Quaternion.AngleAxis(angle, Vector3.forward));
    }
Ejemplo n.º 5
0
    private Vector3 rightJoystickInput; // hold the input of the Right Joystick

    void FixedUpdate()
    {
        // get input from both joysticks
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        float xMovementLeftJoystick = leftJoystickInput.x;   // The horizontal movement from joystick 01
        float zMovementLeftJoystick = leftJoystickInput.y;   // The vertical movement from joystick 01

        float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 02
        float zMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 02


        // if there is only input from the left joystick
        if (leftJoystickInput != Vector3.zero && rightJoystickInput == Vector3.zero)
        {
            if (xMovementLeftJoystick > 0)
            {
            }
            if (xMovementLeftJoystick < 0)
            {
                Debug.Log("SOY X MAYOR A 0");
            }
        }
    }
Ejemplo n.º 6
0
    // Joystick  //
    // Joystick  //
#if UNITY_ANDROID
    void JoystickMovement() //FUNCIÓN AGREGADA POR FAWER
    {
        // get input from both joysticks
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        float xMovementLeftJoystick = leftJoystickInput.x;   // The horizontal movement from joystick 01
        float zMovementLeftJoystick = leftJoystickInput.y;   // The vertical movement from joystick 01

        float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 02
        float zMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 02


        // if there is only input from the left joystick

        if (leftJoystickInput != Vector3.zero && rightJoystickInput == Vector3.zero)
        {
            if (xMovementLeftJoystick > 0.1f)
            {
                RotateRight();
            }
            else if (xMovementLeftJoystick < -0.1f)
            {
                RotateLeft();
            }
        }
        else
        {
            RotateEnd();
        }
    }
Ejemplo n.º 7
0
 private void handleLookAt()
 {
     if (rightJoystick != null)
     {
         Vector3 point = transform.position + new Vector3(rightJoystick.GetInputDirection().x, 0, rightJoystick.GetInputDirection().y);
         controller.LookAt(point);
     }
 }
Ejemplo n.º 8
0
    private void MovimientoCharEnXY()
    {
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            mandoIzq = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

            if (mandoIzq == Vector3.zero)
            {
                _Character.AnimacionEnX(0f);
            }
            else if (mandoIzq != Vector3.zero)
            {
                Vector3 accelXY = new Vector3(mandoIzq.x * _Character.VelocidadXY,
                                              mandoIzq.y * _Character.VelocidadXY,
                                              0f);
                Vector3 velocity = charTransform.localPosition + accelXY * Time.deltaTime;
                Vector3 velFixed = new Vector3(
                    Mathf.Clamp(velocity.x, -_Character.MinRange.x, _Character.MaxRange.x),
                    Mathf.Clamp(velocity.y, -_Character.MinRange.y, _Character.MaxRange.y),
                    velocity.z
                    );

                charTransform.localPosition = velFixed;
                _Character.AnimacionEnX(mandoIzq.x);
            }
        }
        else if (Application.platform == RuntimePlatform.Android)
        {
            // if there is no input on the left joystick
            if (_LeftJoystick.GetInputDirection() == Vector3.zero)
            {
                _Character.AnimacionEnX(0f);
            }
            else if (_LeftJoystick.GetInputDirection() != Vector3.zero)
            {
                Vector3 accelXY = new Vector3(_LeftJoystick.GetInputDirection().x *_Character.VelocidadXY,
                                              _LeftJoystick.GetInputDirection().y *_Character.VelocidadXY,
                                              0f);
                Vector3 velocity = charTransform.localPosition + accelXY * Time.deltaTime;
                Vector3 velFixed = new Vector3(
                    Mathf.Clamp(velocity.x, -_Character.MinRange.x, _Character.MaxRange.x),
                    Mathf.Clamp(velocity.y, -_Character.MinRange.y, _Character.MaxRange.y),
                    velocity.z
                    );

                charTransform.localPosition = velFixed;
                _Character.AnimacionEnX(_LeftJoystick.GetInputDirection().x);
                //aniPlayer.SetFloat(horizontalHash, xAxis, 0.1f, animationSpeed * Time.deltaTime);
            }
        }

        Quaternion newRot = Quaternion.Euler(-10f * _RightJoystick.GetInputDirection().y, 20f * _RightJoystick.GetInputDirection().x, 0f);

        _Character.Model.transform.localRotation = Quaternion.Lerp(_Character.Model.transform.localRotation,
                                                                   newRot, Time.deltaTime * _Character.VelocidadRotacion);

        transform.position += (transform.forward * _Character.VelocidadZ * Time.deltaTime);
    }
Ejemplo n.º 9
0
    private void GetInputs()
    {
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        leftJoystickX = leftJoystickInput.x;
        leftJoystickY = leftJoystickInput.y;

        rightJoystickX = rightJoystickInput.x;
        rightJoytsickY = rightJoystickInput.y;
    }
Ejemplo n.º 10
0
    private void Update()
    {
        lastRotations.Add(rightJoystick.GetInputDirection());
        while (lastRotations.Count > 16)
        {
            lastRotations.RemoveAt(0);
        }

        Quaternion quatA = lastRotations[0];
        Quaternion quatB = lastRotations[1];
        Quaternion quatC = lastRotations[2];
        Quaternion quatD = lastRotations[3];
        Quaternion quatE = lastRotations[4];
        Quaternion quatF = lastRotations[5];
        Quaternion quatG = lastRotations[6];
        Quaternion quatH = lastRotations[7];
        Quaternion quatI = lastRotations[8];
        Quaternion quatJ = lastRotations[9];
        Quaternion quatK = lastRotations[10];
        Quaternion quatL = lastRotations[11];
        Quaternion quatM = lastRotations[12];
        Quaternion quatN = lastRotations[13];
        Quaternion quatO = lastRotations[14];
        Quaternion quatP = lastRotations[15];

        Quaternion quatAB = Quaternion.Lerp(quatA, quatB, 0.5f);
        Quaternion quatCD = Quaternion.Lerp(quatC, quatD, 0.5f);
        Quaternion quatEF = Quaternion.Lerp(quatE, quatF, 0.5f);
        Quaternion quatGH = Quaternion.Lerp(quatG, quatH, 0.5f);
        Quaternion quatIJ = Quaternion.Lerp(quatI, quatJ, 0.5f);
        Quaternion quatKL = Quaternion.Lerp(quatK, quatL, 0.5f);
        Quaternion quatMN = Quaternion.Lerp(quatM, quatN, 0.5f);
        Quaternion quatOP = Quaternion.Lerp(quatO, quatP, 0.5f);

        Quaternion quatABCD = Quaternion.Lerp(quatAB, quatCD, 0.5f);
        Quaternion quatEFGH = Quaternion.Lerp(quatEF, quatGH, 0.5f);
        Quaternion quatIJKL = Quaternion.Lerp(quatIJ, quatKL, 0.5f);
        Quaternion quatMNOP = Quaternion.Lerp(quatMN, quatOP, 0.5f);

        Quaternion quatABCDEFGH = Quaternion.Lerp(quatABCD, quatEFGH, 0.5f);
        Quaternion quatIJKLMNOP = Quaternion.Lerp(quatIJKL, quatMNOP, 0.5f);

        Quaternion quatABCDEFGHIJKLMNOP = Quaternion.Lerp(quatABCDEFGH, quatIJKLMNOP, 0.5f);

        horizontal = rightJoystickInput.x;
        vertical   = rightJoystickInput.y;
        angle      = Mathf.Atan2(horizontal, vertical) * Mathf.Rad2Deg;
        angle      = flipRot ? -angle : angle;
        rotationTarget.rotation = quatABCDEFGHIJKLMNOP;
    }
Ejemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        rightJoystickInput = ArmMover.GetComponent <ArmMover>().maxDistFromX *rightJoystick.GetInputDirection();

        if (GetComponent <Rigidbody>().velocity.y < -4 || GetComponent <Rigidbody>().velocity.y > 4)
        {
            grounded = false;
        }

        if ((rightJoystickInput != Vector3.zero) || (hit))
        {
            playerarm.enabled = true;
            LeanTween.moveX(ArmMover, PHand.transform.position.x + (ArmMover.GetComponent <ArmMover>().maxDistFromX *rightJoystickInput.x), 0.2f);
            LeanTween.moveY(ArmMover, PHand.transform.position.y + (ArmMover.GetComponent <ArmMover>().maxDistFromY *rightJoystickInput.y), 0.2f);
            //ArmMover.transform.position = new Vector3(PHand.transform.position.x + (ArmMover.GetComponent<ArmMover>().maxDistFromX * rightJoystickInput.x), PHand.transform.position.y + (ArmMover.GetComponent<ArmMover>().maxDistFromY * rightJoystickInput.y));

            if (wepactive == false)
            {
                weapon.SetActive(true);
                wepactive = true;
            }
        }
        else
        {
            playerarm.enabled           = false;
            ArmMover.transform.position = new Vector3(PHand.transform.position.x + rightJoystickInput.x, PHand.transform.position.y + rightJoystickInput.y);

            if (wepactive == true)
            {
                weapon.SetActive(false);
                wepactive = false;
            }
        }

        weapon.transform.position = weppos.transform.position;
        // weapon.transform.LookAt(new Vector3(PHand.transform.position.x + (ArmMover.GetComponent<ArmMover>().maxDistFromX * rightJoystickInput.x), PHand.transform.position.y + (ArmMover.GetComponent<ArmMover>().maxDistFromY * rightJoystickInput.y), 0));
    }
    void LateUpdate()
    {
        Vector3 angls = transform.rotation.eulerAngles;
        Vector3 l_vec = l_joy.GetInputDirection();
        Vector3 r_vec = r_joy.GetInputDirection();

        l_vec = l_vec * spd_drg.value;
        r_vec = r_vec * spd_drg.value;

        if (invert_axis)
        {
            transform.Rotate(l_vec.x, l_vec.y, 0);
            transform.Translate(r_vec.x, r_vec.y, 0);
        }
        else
        {
            transform.Rotate(0, l_vec.x, l_vec.y);
            transform.Translate(0, r_vec.x, r_vec.y);
        }
    }
Ejemplo n.º 13
0
 private void FixedUpdate()
 {
     if (enabled)
     {
         leftJoystickInput  = leftJoystick.GetInputDirection();
         rightJoystickInput = rightJoystick.GetInputDirection();
         float xLeftJoystick  = leftJoystickInput.x;
         float yLeftJoystick  = leftJoystickInput.y;
         float xRightJoystick = rightJoystickInput.x;
         float yRightJoystick = rightJoystickInput.y;
         // Left Joystick buttons
         bool W = yLeftJoystick > axisThreshold;
         bool A = xLeftJoystick < -rotationThreshold;
         bool S = yLeftJoystick < -axisThreshold;
         bool D = xLeftJoystick > rotationThreshold;
         // Right Joystick buttons
         bool I = yRightJoystick > axisThreshold;
         bool J = xRightJoystick < -axisThreshold;
         bool K = yRightJoystick < -axisThreshold;
         bool L = xRightJoystick > axisThreshold;
         // Connection to DroneMovementScript
         droneMovement.W = invertJoysticks ? I : W;
         droneMovement.A = invertJoysticks ? J : A;
         droneMovement.S = invertJoysticks ? K : S;
         droneMovement.D = invertJoysticks ? L : D;
         droneMovement.I = invertJoysticks ? W : I;
         droneMovement.J = invertJoysticks ? A : J;
         droneMovement.K = invertJoysticks ? S : K;
         droneMovement.L = invertJoysticks ? D : L;
         // DEBUG Canvas
         leftXText.text   = xLeftJoystick.ToString();
         leftYText.text   = yLeftJoystick.ToString();
         rightXText.text  = xRightJoystick.ToString();
         rightYText.text  = yRightJoystick.ToString();
         leftXText.color  = (A || D) ? Color.green : Color.red;
         leftYText.color  = (W || S) ? Color.green : Color.red;
         rightXText.color = (J || L) ? Color.green : Color.red;
         rightYText.color = (I || K) ? Color.green : Color.red;
     }
 }
Ejemplo n.º 14
0
 private void FixedUpdate()
 {
     timeFirsAtt++;
     yoyoPower--;
     Cooldown--;
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             YoyoMoove      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         YoyoMoove      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         YoyoMoove = DirPlayer.direction / 4f;
     }
     YoyoMoove = YoyoMoove.normalized;
     if (YoyoMoove.magnitude != 0f && Cooldown < 150)
     {
         YoyoPower = YoyoMoove;
     }
     if (Cooldown <= 0)
     {
         if (YoyoMoove.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (YoyoMoove.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
             GoOn            = false;
         }
     }
     if (directionChosen)
     {
         source.PlayOneShot(PowerAbility);
         directionChosen = false;
         yoyoPower       = 30;
         Cooldown        = 200;
         TrailYOYO       = YOYO.GetComponent <ParticleSystem>();
         ParticleSystem.TrailModule trails = TrailYOYO.trails;
         rb.AddForce(new Vector3(0f, 75f, 0f), ForceMode2D.Impulse);
         trails.colorOverLifetime = new Color(1f, 1f, 1f);
         GoOn = true;
     }
     if (Cooldown > 150)
     {
     }
     if (Cooldown <= 0)
     {
         TrailYOYO = YOYO.GetComponent <ParticleSystem>();
         ParticleSystem.TrailModule trails2 = TrailYOYO.trails;
         if (IsBlue)
         {
             trails2.colorOverLifetime = new Color(0f, 1f, 1f);
             GoOn = false;
         }
         else
         {
             trails2.colorOverLifetime = new Color(1f, 1f, 0f);
             GoOn = false;
         }
     }
 }
Ejemplo n.º 15
0
    private void FixedUpdate()
    {
        Cooldown--;
        timeFirsAtt++;
        LineRenderer lineRenderer = filDuGrappin;
        Vector3      position     = base.transform.position;
        float        x            = position.x;
        Vector3      position2    = base.transform.position;

        lineRenderer.SetPosition(0, new Vector3(x, position2.y, -2f));
        LineRenderer lineRenderer2 = filDuGrappin;
        Vector3      position3     = bras.transform.position;
        float        x2            = position3.x;
        Vector3      position4     = bras.transform.position;

        lineRenderer2.SetPosition(1, new Vector3(x2, position4.y, -2f));
        Distance = (bras.transform.position - base.transform.position).magnitude;
        if (!PlayerOneOrTwo)
        {
            if (!SkinChoose.OnePlayer)
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
            else if (!SkinChoose.LeftUser)
            {
                direction      = rightJoystick.GetInputDirection();
                JoystickOnZero = rightJoystick.IsTouching;
            }
            else
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
        }
        else if (!DirPlayer.AI)
        {
            direction      = rightJoystick.GetInputDirection();
            JoystickOnZero = rightJoystick.IsTouching;
        }
        else
        {
            direction = DirPlayer.direction / 4f;
        }
        direction = direction.normalized;
        if (direction.magnitude != 0f)
        {
            power = direction;
        }
        rb.AddForce(direction * speed * Time.deltaTime);
        if (Cooldown <= 0)
        {
            if (direction.magnitude > 0.2f && timeFirsAtt > 100)
            {
                PowerhitReady = true;
            }
            if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
            {
                directionChosen = true;
                PowerhitReady   = false;
            }
        }
        if (directionChosen)
        {
            if (isGrab)
            {
                timeGrab = 60;
                source.PlayOneShot(PowerAbility);
                directionChosen = false;
                rb.drag         = 0f;
                rb.angularDrag  = 1f;
                LineRenderer lineRenderer3 = filDuGrappin;
                Vector3      position5     = base.transform.position;
                float        x3            = position5.x;
                Vector3      position6     = base.transform.position;
                lineRenderer3.SetPosition(0, new Vector3(x3, position6.y, -2f));
                LineRenderer lineRenderer4 = filDuGrappin;
                Vector3      position7     = base.transform.position;
                float        x4            = position7.x;
                Vector3      position8     = base.transform.position;
                lineRenderer4.SetPosition(1, new Vector3(x4, position8.y, -2f));
                GrabStatic.GetComponent <Collider2D>().enabled     = false;
                GrabStatic.GetComponent <SpriteRenderer>().enabled = false;
                GrabShoot.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
                GrabShoot.GetComponent <Collider2D>().enabled      = true;
                GrabShoot.GetComponent <SpriteRenderer>().enabled  = true;
                GrabShoot.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.None;
                GrabShoot.transform.position = GrabStatic.transform.position;
                GrabShoot.transform.rotation = GrabStatic.transform.rotation;
                rb.AddForce(power * shoot * 1.2f, ForceMode2D.Impulse);
                filDuGrappin.gameObject.SetActive(value: true);
            }
            isGrab = false;
        }
        GrabCount--;
        if (GrabCount > 0)
        {
            if (!isGrab)
            {
                Rigidbody2D component  = bras.GetComponent <Rigidbody2D>();
                Vector2     position9  = bras.GetComponent <Rigidbody2D>().position;
                Vector3     position10 = bras.transform.position;
                float       x5         = position10.x;
                Vector3     position11 = base.transform.position;
                float       x6         = x5 - position11.x;
                Vector3     position12 = bras.transform.position;
                float       y          = position12.y;
                Vector3     position13 = base.transform.position;
                Vector2     vector     = new Vector2(x6, y - position13.y);
                component.MovePosition(position9 + vector.normalized * speed * Mathf.Log(Distance) * Time.fixedDeltaTime);
                if (Distance > 5f)
                {
                    Rigidbody2D rigidbody2D = rb;
                    Vector2     position14  = rb.position;
                    Vector3     position15  = bras.transform.position;
                    float       x7          = position15.x;
                    Vector3     position16  = base.transform.position;
                    float       x8          = x7 - position16.x;
                    Vector3     position17  = bras.transform.position;
                    float       y2          = position17.y;
                    Vector3     position18  = base.transform.position;
                    Vector2     vector2     = new Vector2(x8, y2 - position18.y);
                    rigidbody2D.MovePosition(position14 + vector2.normalized * ((0f - speed) / 4f) * Time.fixedDeltaTime);
                }
            }
            if (Distance < 2f)
            {
                GrabStatic.GetComponent <Collider2D>().enabled     = true;
                GrabStatic.GetComponent <SpriteRenderer>().enabled = true;
                GrabShoot.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
                GrabShoot.GetComponent <Collider2D>().enabled      = false;
                GrabShoot.GetComponent <SpriteRenderer>().enabled  = false;
                LineRenderer lineRenderer5 = filDuGrappin;
                Vector3      position19    = base.transform.position;
                float        x9            = position19.x;
                Vector3      position20    = base.transform.position;
                lineRenderer5.SetPosition(0, new Vector3(x9, position20.y, -2f));
                LineRenderer lineRenderer6 = filDuGrappin;
                Vector3      position21    = base.transform.position;
                float        x10           = position21.x;
                Vector3      position22    = base.transform.position;
                lineRenderer6.SetPosition(1, new Vector3(x10, position22.y, -2f));
                filDuGrappin.gameObject.SetActive(value: false);
                isGrab    = true;
                GrabCount = 0;
            }
        }
        else
        {
            GrabStatic.GetComponent <Rigidbody2D>().AddForce(direction * maniment * Time.fixedDeltaTime);
        }
        if (timeGrab > 0)
        {
            timeGrab--;
        }
        if (timeGrab == 1)
        {
            if (directionChosen)
            {
                directionChosen = false;
                base.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0f, 0f);
            }
            GrabStatic.GetComponent <Collider2D>().enabled     = true;
            GrabStatic.GetComponent <SpriteRenderer>().enabled = true;
            GrabShoot.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
            GrabShoot.GetComponent <Collider2D>().enabled      = false;
            GrabShoot.GetComponent <SpriteRenderer>().enabled  = false;
            filDuGrappin.gameObject.SetActive(value: false);
            isGrab    = true;
            GrabCount = 0;
            LineRenderer lineRenderer7 = filDuGrappin;
            Vector3      position23    = base.transform.position;
            float        x11           = position23.x;
            Vector3      position24    = base.transform.position;
            lineRenderer7.SetPosition(0, new Vector3(x11, position24.y, -2f));
            LineRenderer lineRenderer8 = filDuGrappin;
            Vector3      position25    = base.transform.position;
            float        x12           = position25.x;
            Vector3      position26    = base.transform.position;
            lineRenderer8.SetPosition(1, new Vector3(x12, position26.y, -2f));
        }
    }
Ejemplo n.º 16
0
 private void FixedUpdate()
 {
     timeFirsAtt++;
     Cooldown--;
     rb.AddForce(direction * maniment * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             direction      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         direction      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         direction = DirPlayer.direction / 4f;
     }
     direction = direction.normalized;
     if (direction.magnitude != 0f)
     {
         Power = direction;
     }
     if (Cooldown <= 0)
     {
         if (!PlayerOneOrTwo)
         {
         }
         if (direction.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
         if (isBlue)
         {
             symboleUlt.GetComponent <SpriteRenderer>().color = new Color(0f, 1f, 1f);
         }
         else
         {
             symboleUlt.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 0f);
         }
     }
     if (FireCooldown > 0)
     {
         FireCooldown--;
         if (FireCooldown == 2)
         {
             symboleUlt.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f);
             maniment /= 10f;
             fire.SetActive(value: false);
         }
     }
     if (directionChosen)
     {
         source.PlayOneShot(PowerAbility);
         Cooldown        = 375;
         directionChosen = false;
         fire.SetActive(value: true);
         FireCooldown = 150;
         maniment    *= 10f;
         StatePower   = UnityEngine.Random.Range(0, 3);
         symboleUlt.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.3f);
     }
 }
Ejemplo n.º 17
0
 private void FixedUpdate()
 {
     Jambecode1.WeaponMoove = Powerhit;
     Jambecode2.WeaponMoove = Powerhit;
     if (!PlayerOneOrTwo)
     {
         if (RecupHit < 30)
         {
             if (!SkinChoose.OnePlayer)
             {
                 direction      = leftJoystick.GetInputDirection();
                 JoystickOnZero = leftJoystick.IsTouching;
             }
             else if (!SkinChoose.LeftUser)
             {
                 direction      = rightJoystick.GetInputDirection();
                 JoystickOnZero = rightJoystick.IsTouching;
             }
             else
             {
                 direction      = leftJoystick.GetInputDirection();
                 JoystickOnZero = leftJoystick.IsTouching;
             }
         }
         else
         {
             direction = Powerhit / 2f;
         }
         if (direction.magnitude != 0f)
         {
             Powerhit = direction * 2f;
         }
     }
     else
     {
         if (RecupHit < 30)
         {
             if (!DirPlayer.AI)
             {
                 direction      = rightJoystick.GetInputDirection();
                 JoystickOnZero = rightJoystick.IsTouching;
             }
             else
             {
                 direction = DirPlayer.direction / 4f;
             }
         }
         else
         {
             direction = Powerhit / 2f;
         }
         if (direction.magnitude != 0f)
         {
             Powerhit = direction * 2f;
         }
     }
     direction = direction.normalized;
     if (direction.magnitude > 0.2f && timeFirsAtt > 100)
     {
         PowerhitReady = true;
     }
     if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
     {
         directionChosen = true;
         PowerhitReady   = false;
     }
     timeFirsAtt++;
     if (Propulsion <= -3.4f && zeroAtteintGaz)
     {
         zeroAtteintGaz         = false;
         SwordCharge.startColor = Base;
     }
     if (zeroAtteintGaz)
     {
         Powerhit = new Vector2(0f, 0f);
     }
     if (RecupHit > 0)
     {
         RecupHit--;
         if (Propulsion <= 0f)
         {
             Propulsion += 0.07f;
             SwordCharge.SetPosition(1, new Vector3(0f, Propulsion));
             if (Powerhit.x < 0f)
             {
                 rbSword.AddRelativeForce(new Vector2(0f, speed2) * Time.fixedDeltaTime);
             }
             if (Powerhit.x > 0f)
             {
                 rbSword.AddRelativeForce(new Vector2(0f, 0f - speed2) * Time.fixedDeltaTime);
             }
         }
         else
         {
             Powerhit.x = 0f;
             Powerhit.y = 0f;
             Propulsion = 0f;
             Gaz.SetActive(value: false);
             zeroAtteintGaz = true;
         }
     }
     else
     {
         rbSword.AddForce(direction * maniment * Time.fixedDeltaTime);
     }
     if (!directionChosen)
     {
         return;
     }
     SwordCharge.SetPosition(1, new Vector3(0f, Propulsion));
     if (Propulsion <= -3.4f && timeFirsAtt > 100)
     {
         source.PlayOneShot(PowerAbility);
         RecupHit = 100;
         if (Powerhit.x > 0.1f)
         {
             direction.x = 0.12f;
         }
         if (Powerhit.x < -0.1f)
         {
             direction.x = -0.12f;
         }
         Gaz.SetActive(value: true);
         SwordCharge.startColor = new Color(0f, 0f, 0f);
     }
     if (RecupHit < 99)
     {
         direction.x = 0f;
         direction.y = 0f;
     }
     directionChosen = false;
 }
    void FixedUpdate()
    {
        float tempClamp = parentCameraTarget.transform.localEulerAngles.x;

        //Debug.Log("CURRENT ANGLE -->" + tempClamp);

        // get input from both joysticks
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        float xMovementLeftJoystick = leftJoystickInput.x;   // The horizontal movement from joystick 01
        float zMovementLeftJoystick = leftJoystickInput.y;   // The vertical movement from joystick 01

        float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 01
        float yMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 01

        // if there is no input on the left joystick
        if (leftJoystickInput == Vector3.zero || rightJoystickInput == Vector3.zero)
        {
            animator.SetBool("isRunning", false);
            //Debug.Log("test");
        }


        // if there is only input from the left joystick
        if (leftJoystickInput != Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngle = Mathf.Atan2(zMovementLeftJoystick, xMovementLeftJoystick);
            xMovementLeftJoystick *= Mathf.Abs(Mathf.Cos(tempAngle));
            zMovementLeftJoystick *= Mathf.Abs(Mathf.Sin(tempAngle));

            //Debug.Log(xMovementLeftJoystick + ", " + zMovementLeftJoystick);
            leftJoystickInput  = new Vector3(xMovementLeftJoystick, 0, zMovementLeftJoystick);
            leftJoystickInput  = transform.TransformDirection(leftJoystickInput);
            leftJoystickInput *= moveSpeed;

            // rotate the player to face the direction of input
            Vector3 temp = transform.position;
            temp.x += xMovementLeftJoystick;
            temp.z += zMovementLeftJoystick;
            Vector3 lookDirection = temp - transform.position;
            if (lookDirection != Vector3.zero)
            {
                //    rotationTarget.localRotation = Quaternion.Slerp(rotationTarget.localRotation, Quaternion.LookRotation(lookDirection), rotationSpeed * Time.deltaTime);
            }
            if (animator != null)
            {
                animator.SetBool("isRunning", true);
            }

            // move the player
            //rigidBody.transform.Translate(leftJoystickInput * Time.fixedDeltaTime);


            // START HERE -----------------------------------------------------------------------------------------------------------------------------

            moveSpeed     = Mathf.Abs(zMovementLeftJoystick * moveSpeedMultiplier);
            rotationSpeed = Mathf.Abs(xMovementLeftJoystick * 200);

            if (zMovementLeftJoystick > 0)
            {
                //Debug.Log("FOWARD");
                transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
            }

            if (zMovementLeftJoystick < 0)
            {
                transform.Translate(Vector3.back * moveSpeed * Time.deltaTime);
                //Debug.Log("BACKWARD");
            }

            if (xMovementLeftJoystick > 0)
            {
                transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime);
                //Debug.Log("RIGHT");
            }

            if (xMovementLeftJoystick < 0)
            {
                transform.Rotate(-Vector3.up * rotationSpeed * Time.deltaTime);
                //Debug.Log("LEFT");
            }

            //Debug.Log(moveSpeed + " - " + rotationSpeed);

            // START HERE -----------------------------------------------------------------------------------------------------------------------------
        }

        // if there is only input from the right joystick
        if (rightJoystickInput != Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngleRight = Mathf.Atan2(yMovementRightJoystick, xMovementRightJoystick);
            xMovementRightJoystick *= Mathf.Abs(Mathf.Cos(tempAngleRight));
            yMovementRightJoystick *= Mathf.Abs(Mathf.Sin(tempAngleRight));

            //Debug.Log(xMovementRightJoystick + ", " + yMovementRightJoystick);
            rightJoystickInput  = new Vector3(xMovementRightJoystick, yMovementRightJoystick, 0);
            rightJoystickInput  = parentCameraTarget.transform.TransformDirection(rightJoystickInput);
            rightJoystickInput *= moveSpeed;

            //Debug.Log("rightJoystickInput:" + rightJoystickInput);

            // rotate the player to face the direction of input
            Vector3 tempRight = cameraTarget.transform.position;
            tempRight.x += xMovementRightJoystick;
            tempRight.y += yMovementRightJoystick;
            tempRight.z  = 0f;

            //Debug.Log("lookDirection:" + tempRight);

            Vector3 lookDirectionRight = tempRight - cameraTarget.transform.position;

            //Debug.Log("lookDirection:" + lookDirectionRight);

            xCameraRotationSpeed = Mathf.Abs(xMovementRightJoystick * 200);
            yCameraRotationSpeed = Mathf.Abs(yMovementRightJoystick * 200);

            float rotToPos = Mathf.Abs(yMovementRightJoystick * 360f);
            float rotToNeg = 360f - (Mathf.Abs(yMovementRightJoystick * 360f));

            //Debug.Log("POS: " + rotToPos + ", NEG: " + rotToNeg);


            //apple += yMovementRightJoystick * yCameraRotationSpeed * Time.deltaTime;
            //parentCameraTarget.localRotation = Quaternion.Euler(-apple, 0f, 0f);
            Debug.Log(Input.GetAxis("Mouse Y"));
            float      rotationYInput = yMovementRightJoystick * 500f * Time.deltaTime;
            Quaternion yQuaternion    = Quaternion.AngleAxis(rotationYInput, -Vector3.right);
            Quaternion temp           = parentCameraTarget.localRotation * yQuaternion;
            if (Quaternion.Angle(center, temp) < this.maxAngle)
            {
                parentCameraTarget.localRotation = temp;
            }


            //parentCameraTarget.localRotation = Quaternion.Slerp(parentCameraTarget.localRotation, Quaternion.LookRotation(new Vector3(0f, 1f, 0f)), Time.deltaTime * cameraRotationResetSpeed);
            //Quaternion rot = parentCameraTarget.transform.localRotation;
            //rot.eulerAngles = new Vector3 (apple, 0f, 0f);
            //parentCameraTarget.transform.localRotation = rot;
            //parentCameraTarget.transform.localEulerAngles = Quaternion.Euler(0f,apple,0f);
            //Debug.Log(yMovementRightJoystick + "--> " + apple);

            /*
             * //GLOBAL VAR
             * bool rotDirection = true;
             * //------------------------
             *
             * if(yxMovementRightJoystick > 0) {
             *      rotDirection = true;
             * }
             *
             * if(yMovementRightJoystick < 0) {
             *      rotDirection = false;
             * }
             *
             * if(rotDirection == true){
             *
             * } else {
             *
             * }
             *
             *
             */

            if (xMovementRightJoystick > 0)
            {
                //Debug.Log("RIGHT → " + cameraTarget.transform);
                //cameraTarget.transform.Rotate(new Vector3(0f, 1f, 0f) * xCameraRotationSpeed * Time.deltaTime);
            }

            if (xMovementRightJoystick < 0)
            {
                //Debug.Log("← LEFT" + cameraTarget.transform);
                //cameraTarget.transform.Rotate(new Vector3(0f, -1f, 0f) * xCameraRotationSpeed * Time.deltaTime);
            }

            if (yMovementRightJoystick > 0)
            {
                //Debug.Log(yMovementRightJoystick + "UP ↑ " + tempClamp);

                if (tempClamp > 315f || tempClamp < 45f)
                {
                    //parentCameraTarget.transform.Rotate(new Vector3(-1f, 0f, 0f) * yCameraRotationSpeed * Time.deltaTime);
                }
            }

            if (yMovementRightJoystick < 0)
            {
                //Debug.Log("DOWN ↓ " + tempClamp);
                // Check if the joystick is not floored to release the y lock
                if (yMovementRightJoystick > -0.98f)
                {
                    if (tempClamp > 315f || tempClamp < 45f)
                    {
                        //parentCameraTarget.transform.Rotate(new Vector3(1f, 0f, 0f) * yCameraRotationSpeed * Time.deltaTime);
                    }
                }
            }
        }
        else if (leftJoystickInput != Vector3.zero && rightJoystickInput == Vector3.zero)
        {
            // if the joystick is released then snap back to 0,0
            // UNCOMMENT TO SNAP THE CAMERA BACK TO STARTING POINT
            parentCameraTarget.localRotation = Quaternion.Slerp(parentCameraTarget.localRotation, Quaternion.LookRotation(Vector3.zero), Time.deltaTime * cameraRotationResetSpeed);
            //cameraTarget.localRotation = Quaternion.Slerp(cameraTarget.localRotation, Quaternion.LookRotation(Vector3.zero), Time.deltaTime * cameraRotationResetSpeed);
        }
        else
        {
            //parentCameraTarget.localRotation = Quaternion.Slerp(parentCameraTarget.localRotation, Quaternion.LookRotation(Vector3.zero), Time.deltaTime * cameraRotationResetSpeed);
        }
    }
Ejemplo n.º 19
0
 private void FixedUpdate()
 {
     if (!active)
     {
         return;
     }
     if (!PlayerOneOrTwo)
     {
         if (RecupHit < 30)
         {
             direction = leftJoystick.GetInputDirection();
         }
         else
         {
             direction = Powerhit / 2f;
         }
         if (direction.magnitude != 0f)
         {
             Powerhit = direction * 2f;
         }
     }
     else
     {
         if (RecupHit < 30)
         {
             direction = rightJoystick.GetInputDirection();
         }
         else
         {
             direction = Powerhit / 2f;
         }
         if (direction.magnitude != 0f)
         {
             Powerhit = direction * 2f;
         }
     }
     direction = direction.normalized;
     if (direction.magnitude > 0.2f && timeFirsAtt > 100)
     {
         PowerhitReady = true;
     }
     if (direction.magnitude == 0f && PowerhitReady)
     {
         directionChosen = true;
         PowerhitReady   = false;
     }
     timeFirsAtt++;
     if (Propulsion <= -3.4f && zeroAtteintGaz)
     {
         zeroAtteintGaz         = false;
         SwordCharge.startColor = Base;
     }
     if (RecupHit > 0)
     {
         RecupHit--;
         if (Propulsion <= 0f)
         {
             Propulsion += 0.07f;
             SwordCharge.SetPosition(1, new Vector3(0f, Propulsion));
             rb.MovePosition(rb.position + Powerhit * speed2 * Time.fixedDeltaTime);
         }
         else
         {
             Powerhit.x = 0f;
             Powerhit.y = 0f;
             Propulsion = 0f;
             Gaz.SetActive(value: false);
             zeroAtteintGaz = true;
         }
     }
     if (choctime < 1)
     {
         if (RecupHit <= 30)
         {
             rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
         }
     }
     else
     {
         choctime--;
     }
     if (!directionChosen)
     {
         return;
     }
     SwordCharge.SetPosition(1, new Vector3(0f, Propulsion));
     if ((double)Propulsion <= -3.1 && timeFirsAtt > 100)
     {
         RecupHit = 100;
         if (Powerhit.x > 0.1f)
         {
             direction.x = 0.12f;
         }
         if (Powerhit.x < -0.1f)
         {
             direction.x = -0.12f;
         }
         Gaz.SetActive(value: true);
         SwordCharge.startColor = new Color(0f, 0f, 0f);
     }
     if (RecupHit < 99)
     {
         direction.x = 0f;
         direction.y = 0f;
     }
     directionChosen = false;
 }
Ejemplo n.º 20
0
    private void FixedUpdate()
    {
        CoolDownShoot++;
        Cooldown--;
        timeFirsAtt++;
        if (Cooldown > 220)
        {
            rb.MovePosition(rb.position + Power * speed * Time.fixedDeltaTime);
        }
        else
        {
            rb.constraints = RigidbodyConstraints2D.None;
        }
        if (!PlayerOneOrTwo)
        {
            if (!SkinChoose.OnePlayer)
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
            else if (!SkinChoose.LeftUser)
            {
                direction      = rightJoystick.GetInputDirection();
                JoystickOnZero = rightJoystick.IsTouching;
            }
            else
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
        }
        else if (!DirPlayer.AI)
        {
            direction      = rightJoystick.GetInputDirection();
            JoystickOnZero = rightJoystick.IsTouching;
        }
        else
        {
            direction = DirPlayer.direction / 4f;
        }
        direction = direction.normalized;
        rb.AddForce(direction * maniment * Time.fixedDeltaTime);
        if (direction.magnitude != 0f)
        {
            Power = direction;
        }
        if (Cooldown <= 0)
        {
            gunsprite.color = new Color(0f, 0f, 0f);
            if (direction.magnitude > 0.2f && timeFirsAtt > 100)
            {
                PowerhitReady = true;
            }
            if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
            {
                directionChosen = true;
                PowerhitReady   = false;
            }
        }
        else if (!PlayerOneOrTwo)
        {
            gunsprite.color = new Color(1f, 1f, 1f);
        }
        else
        {
            gunsprite.color = new Color(1f, 1f, 1f);
        }
        if (!directionChosen)
        {
            return;
        }
        Cooldown        = 90;
        directionChosen = false;
        source.PlayOneShot(PowerAbility);
        int num = 0;

        while (true)
        {
            if (num < SuperBullet.Length)
            {
                if (!SuperBullet[num].activeInHierarchy)
                {
                    break;
                }
                num++;
                continue;
            }
            return;
        }
        SuperBullet[num].transform.position = base.transform.position;
        SuperBullet[num].transform.rotation = base.transform.rotation;
        SuperBullet[num].SetActive(value: true);
        BulletSpeed.x = Speed;
        SuperBullet[num].GetComponent <Rigidbody2D>().AddForce(Power * Speed, ForceMode2D.Impulse);
        SuperBullet[num].GetComponent <Rigidbody2D>().AddTorque(Speed * 2f);
        rb.MovePosition(rb.position + Power * speed / 2f * Time.fixedDeltaTime);
    }
Ejemplo n.º 21
0
    private void FixedUpdate()
    {
        CoolDownShoot++;
        Cooldown--;
        timeFirsAtt++;
        if (Cooldown > 220)
        {
            rb.MovePosition(rb.position + Power * speed * Time.fixedDeltaTime);
        }
        else
        {
            rb.constraints = RigidbodyConstraints2D.None;
        }
        if (!PlayerOneOrTwo)
        {
            if (!SkinChoose.OnePlayer)
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
            else if (!SkinChoose.LeftUser)
            {
                direction      = rightJoystick.GetInputDirection();
                JoystickOnZero = rightJoystick.IsTouching;
            }
            else
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
        }
        else if (!DirPlayer.AI)
        {
            direction      = rightJoystick.GetInputDirection();
            JoystickOnZero = rightJoystick.IsTouching;
        }
        else
        {
            direction = DirPlayer.direction / 4f;
        }
        direction = direction.normalized;
        Rigidbody2D rigidbody2D = rb;
        Vector2     force       = direction * maniment;
        Vector3     position    = base.transform.position;
        float       x           = position.x;
        Vector3     position2   = base.transform.position;

        rigidbody2D.AddForceAtPosition(force, new Vector2(x, position2.y) + direction * 5f);
        if (direction.magnitude != 0f)
        {
            Power = direction;
        }
        if (Cooldown <= 0)
        {
            if (!PlayerOneOrTwo)
            {
            }
            if (direction.magnitude > 0.2f && timeFirsAtt > 100)
            {
                PowerhitReady = true;
            }
            if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
            {
                directionChosen = true;
                PowerhitReady   = false;
            }
        }
        if (directionChosen)
        {
            directionChosen = false;
            BulletSpeed.x   = 0f - Speed;
            if (TimePortal == 0)
            {
                source.PlayOneShot(PowerAbility1);
                Cooldown   = 20;
                TimePortal = 1;
                SuperBullet2.transform.position = base.transform.position;
                SuperBullet2.transform.rotation = base.transform.rotation;
                SuperBullet2.SetActive(value: true);
                SuperBullet2.GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed, ForceMode2D.Impulse);
            }
            else
            {
                source.PlayOneShot(PowerAbility2);
                Cooldown   = 20;
                TimePortal = 0;
                SuperBullet1.transform.position = base.transform.position;
                SuperBullet1.transform.rotation = base.transform.rotation;
                SuperBullet1.SetActive(value: true);
                SuperBullet1.GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed, ForceMode2D.Impulse);
            }
        }
        if (ReloadTime > 0)
        {
            ReloadTime--;
        }
        if (timeFirsAtt > 100 && direction.magnitude != 0f && ReloadTime < 1 && CoolDownShoot >= 40)
        {
            CoolDownShoot = 0;
        }
    }
Ejemplo n.º 22
0
 private void FixedUpdate()
 {
     if (DoubleActive)
     {
         rb.AddForceAtPosition(direction * 15f * Time.fixedDeltaTime, base.transform.position, ForceMode2D.Impulse);
     }
     timeFirsAtt++;
     Cooldown--;
     rb.AddForce(direction * maniment * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             direction      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         direction      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         direction = DirPlayer.direction / 4f;
     }
     direction = direction.normalized;
     if (direction.magnitude != 0f)
     {
         Power = direction;
     }
     if (Cooldown <= 0)
     {
         if (direction.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
     }
     if (MainSabre && Cooldown == 1)
     {
         forceEclairPower.gameObject.GetComponent <BoxCollider2D>().enabled = false;
     }
     if (!directionChosen)
     {
         return;
     }
     source.PlayOneShot(PowerAbility);
     Cooldown        = 10;
     directionChosen = false;
     if (!MainSabre)
     {
         return;
     }
     if (!DoubleActive)
     {
         DoubleActive = true;
         base.gameObject.GetComponent <BoxCollider2D>().offset = new Vector2(0f, -1.610428f);
         base.gameObject.GetComponent <BoxCollider2D>().size   = new Vector2(0.27f, 8.0871f);
         AutreSabre.SetActive(value: false);
         doubleSabreApp.SetActive(value: true);
         saberStat.DAMAGE               = 0.068f;
         saberStat.chocpowerMember      = 20f;
         saberStat.chocpowerSmallMember = 25f;
         saberStat.chocpowerWeapon      = 7f;
         JointAngleLimits2D limits = mainHing.limits;
         limits.min      = -180f;
         limits.max      = 180f;
         mainHing.limits = limits;
     }
     else
     {
         DoubleActive = false;
         base.gameObject.GetComponent <BoxCollider2D>().offset = new Vector2(0f, -0.0724f);
         base.gameObject.GetComponent <BoxCollider2D>().size   = new Vector2(0.27f, 5.011055f);
         AutreSabre.transform.position = base.transform.position;
         AutreSabre.SetActive(value: true);
         doubleSabreApp.SetActive(value: false);
         saberStat.DAMAGE               = 0.03f;
         saberStat.chocpowerMember      = 15f;
         saberStat.chocpowerSmallMember = 20f;
         saberStat.chocpowerWeapon      = 5f;
         JointAngleLimits2D limits2 = mainHing.limits;
         limits2.min     = -90f;
         limits2.max     = 90f;
         mainHing.limits = limits2;
     }
     if (powerAcitavtion)
     {
         powerAcitavtion = false;
         if (power == 3)
         {
             float num = Mathf.Atan2(Power.y, Power.x) * 57.29578f;
             forceEclair.gameObject.SetActive(value: false);
             forceEclairPower.gameObject.transform.position = rb.transform.position;
             forceEclairPower.gameObject.transform.rotation = Quaternion.Euler(0f, 0f, num - 90f);
             forceEclairPower.gameObject.SetActive(value: false);
             forceEclairPower.gameObject.GetComponent <BoxCollider2D>().enabled = true;
             forceEclairPower.gameObject.SetActive(value: true);
             source.PlayOneShot(PowerAbilityElectric, 0.7f);
         }
         if (power == 5)
         {
             forcePunch.gameObject.SetActive(value: false);
             float num2 = Mathf.Atan2(Power.y, Power.x) * 57.29578f;
             forcePunchPower.gameObject.transform.position = rb.transform.position;
             forcePunchPower.gameObject.transform.rotation = Quaternion.Euler(0f, 0f, num2 - 90f);
             forcePunchPower.gameObject.GetComponent <BoxCollider2D>().enabled = true;
             forcePunchPower.gameObject.SetActive(value: true);
             source.PlayOneShot(PowerAbilityForcePunch, 0.8f);
         }
     }
 }
Ejemplo n.º 23
0
 private void FixedUpdate()
 {
     PowerWeapon--;
     stunBras /= 1.4f;
     Charge--;
     if (!AI)
     {
         if (!PlayerOneOrTwo)
         {
             if (!SkinChoose.OnePlayer)
             {
                 direction = leftJoystick.GetInputDirection();
             }
             else if (!SkinChoose.LeftUser)
             {
                 direction = rightJoystick.GetInputDirection();
             }
             else
             {
                 direction = leftJoystick.GetInputDirection();
             }
         }
         else
         {
             direction = rightJoystick.GetInputDirection();
         }
     }
     else if (PowerWeapon < 0)
     {
         if (Charge < 0)
         {
             if (!SkinChoose.TwoPlayerSurvival)
             {
                 direction = (GameObject.Find("Corps").transform.position - base.transform.position).normalized;
             }
             else
             {
                 if (AiSuivrePlayer == 0)
                 {
                     direction = (GameObject.Find("Corps").transform.position - base.transform.position).normalized;
                 }
                 if (AiSuivrePlayer == 1)
                 {
                     if (!SkinChoose.TwoPlayerSurvival)
                     {
                         direction = (GameObject.Find("Corps").transform.position - base.transform.position).normalized;
                     }
                     else
                     {
                         direction = (GameObject.Find("Corps d").transform.position - base.transform.position).normalized;
                     }
                 }
             }
         }
     }
     else
     {
         direction = new Vector2(0f, 0f);
     }
     direction = new Vector2(direction.x + Devx, direction.y + Devy);
     direction = direction.normalized * ability;
     if (direction.y > 0f)
     {
         direction.y *= DirectionHaut;
     }
     if (IsHuman)
     {
         if (ColTime > 30)
         {
             if (direction.y > 0.7f)
             {
                 if (AbilityBarre != null)
                 {
                     lol = ((float)AbilityControl + 1f) / 41f;
                     AbilityBarre.color = new Color(lol, lol, lol, lol);
                     AbilityBarre.transform.localScale = new Vector3(lol * 3f, 0.27f, 1f);
                 }
                 AbilityControl++;
             }
             else if (direction.y < -0.8f)
             {
                 if (AbilityBarre != null)
                 {
                     lol = ((float)AbilityControl + 1f) / 61f;
                     AbilityBarre.color = new Color(lol, lol, lol, lol);
                     AbilityBarre.transform.localScale = new Vector3(lol * 3f, 0.27f, 1f);
                 }
                 AbilityControl++;
             }
             else
             {
                 if (AbilityBarre != null)
                 {
                     AbilityBarre.color = new Color(0f, 0f, 0f, 0f);
                     AbilityBarre.transform.localScale = new Vector3(0f, 0f, 0f);
                 }
                 AbilityControl = 0;
             }
         }
         else
         {
             AbilityControl = 0;
             if (AbilityBarre != null)
             {
                 AbilityBarre.color = new Color(0f, 0f, 0f, 0f);
                 AbilityBarre.transform.localScale = new Vector3(0f, 0f, 0f);
             }
         }
         if (Shield.gameObject != null && !Shield.gameObject.activeInHierarchy)
         {
             ShieldIntensity++;
             if (ShieldIntensity == 100)
             {
                 Shield.GetComponent <DestroyInTime>().timeToDesactive = 140;
                 Shield.GetComponent <BouclierAbility>().sizeMax       = 6f;
             }
         }
         if (AbilityControl == 45)
         {
             AbilityControl = 0;
             if (AbilityBarre != null)
             {
                 AbilityBarre.color = new Color(0f, 0f, 0f, 0f);
                 AbilityBarre.transform.localScale = new Vector3(0f, 0f, 0f);
             }
             if (direction.y > 0.7f)
             {
                 RelativeCorpsPoint.AddForce(direction * 175f, ForceMode2D.Impulse);
                 source.PlayOneShot(PowerJump);
             }
             if (direction.y < -0.8f && Shield.gameObject != null)
             {
                 Shield.transform.position = RelativeCorpsPoint.transform.position;
                 float num = Shield.GetComponent <DestroyInTime>().timeToDesactive;
                 Shield.GetComponent <DestroyInTime>().timeToDesactive = (int)(num / 1.4f);
                 Shield.GetComponent <BouclierAbility>().sizeMax       = Shield.GetComponent <BouclierAbility>().sizeMax / 1.4f;
                 Shield.gameObject.SetActive(value: false);
                 Shield.gameObject.SetActive(value: true);
                 timeShield      = 10;
                 ShieldIntensity = 0;
                 if (Shield.GetComponent <BouclierAbility>().sizeMax / 6f > 0.2f)
                 {
                     source.PlayOneShot(PowerBlock, 1f);
                 }
             }
         }
         if (timeShield > 0)
         {
             timeShield--;
             if (timeShield != 1)
             {
                 RelativeCorpsPoint.velocity = new Vector2(0f, 0f);
             }
         }
     }
     if (ColTime > 0)
     {
         DirectionHaut = 1f;
         ColTime--;
     }
     else
     {
         DirectionHaut = 0f;
     }
     if (stunBras <= 1f)
     {
         rb.MovePosition(rb.position + direction * speed * PauseCherche * Time.fixedDeltaTime);
         ability = 1f;
     }
 }
Ejemplo n.º 24
0
    void FixedUpdate()
    {
        if (!controllable)
        {
            return;
        }

        bool  shot    = false;
        float gunTime = getGunTime();

        if (gunTime > -1f)
        {
            time += Time.deltaTime;
            if (time >= gunTime)
            {
                time = 0f;
                shot = true;
            }
        }
        else
        {
            time = 0f;
        }

        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        Vector3 v = new Vector3(leftJoystickInput.x, leftJoystickInput.y, 0f);

        transform.position += v * Time.deltaTime * moveSpeed;

        float a;

        if (rightJoystickInput.x == 0 && rightJoystickInput.y == 0)
        {
            a = Mathf.Atan2(leftJoystickInput.x, leftJoystickInput.y) * Mathf.Rad2Deg;
        }
        else
        {
            a = Mathf.Atan2(rightJoystickInput.x, rightJoystickInput.y) * Mathf.Rad2Deg;

            playGun();
        }

        if (a == 0)
        {
            a = angle;
        }
        else
        {
            angle = a;
        }

        if (!(rightJoystickInput.x == 0 && rightJoystickInput.y == 0) && spawn != null && shot && bullets > 0)
        {
            playGun();

            if (bullets == 0 && gun != Gun.ARMS)
            {
                SetGun(Gun.ARMS);
            }
        }

        toRotation = Quaternion.Euler(new Vector3(0, 0, -a));
        GameObject.FindGameObjectWithTag("BulletsCounter").GetComponent <Text>().text = bullets.ToString();
    }
Ejemplo n.º 25
0
 private void FixedUpdate()
 {
     distance = (Bras.transform.position - base.transform.position).magnitude;
     timeFirsAtt++;
     yoyoPower--;
     Cooldown--;
     rb.AddForce(YoyoMoove * maniment * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             YoyoMoove      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         YoyoMoove      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         YoyoMoove = DirPlayer.direction / 4f;
     }
     YoyoMoove = YoyoMoove.normalized;
     if (YoyoMoove.magnitude != 0f && Cooldown < 150)
     {
         YoyoPower = YoyoMoove;
     }
     if (Cooldown <= 0)
     {
         if (YoyoMoove.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (YoyoMoove.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
     }
     if (directionChosen)
     {
         if (Power == 0)
         {
             source.PlayOneShot(PowerAbility);
             yoyoPower = 30;
             rb.GetComponent <Transform>().localScale = base.transform.localScale * 1.7f;
             rb.drag = 10000f;
         }
         else
         {
             Shockwave.transform.position = base.transform.position;
             Shockwave.transform.rotation = base.transform.rotation;
             Shockwave.transform.Rotate(0f, 0f, -90f, Space.Self);
             Shockwave.SetActive(value: true);
             Shockwave.GetComponent <Rigidbody2D>().AddRelativeForce(new Vector2(0f, 60f), ForceMode2D.Impulse);
             source.PlayOneShot(ShockWave);
         }
         ImageIsReady.color = new Color(0.7f, 0.7f, 0.7f);
         Cooldown           = 200;
         directionChosen    = false;
     }
     if (Power == 0)
     {
         if (Cooldown == 120)
         {
             rb.drag = 0f;
             rb.GetComponent <Transform>().localScale = base.transform.localScale / 1.7f;
         }
         if (yoyoPower <= 0)
         {
             rb.constraints = RigidbodyConstraints2D.None;
             Bras.GetComponent <Rigidbody2D>().constraints      = RigidbodyConstraints2D.None;
             avantBras.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.None;
             Corps.GetComponent <Rigidbody2D>().constraints     = RigidbodyConstraints2D.None;
         }
         if (Cooldown > 150)
         {
             rb.constraints = RigidbodyConstraints2D.FreezeRotation;
             Bras.GetComponent <Rigidbody2D>().constraints      = RigidbodyConstraints2D.FreezeRotation;
             avantBras.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
             Corps.GetComponent <Rigidbody2D>().constraints     = RigidbodyConstraints2D.FreezeRotation;
             rb.MovePosition(rb.position + YoyoPower * 40f * Time.fixedDeltaTime);
         }
     }
     if (Cooldown != 0)
     {
         return;
     }
     Power = UnityEngine.Random.Range(0, 2);
     if (Power == 0)
     {
         if (IsBlue)
         {
             ImageIsReady.color = new Color(0f, 1f, 1f);
         }
         else
         {
             ImageIsReady.color = new Color(1f, 1f, 0f);
         }
     }
     else
     {
         ImageIsReady.color = new Color(1f, 0f, 0f);
     }
 }
Ejemplo n.º 26
0
 private void FixedUpdate()
 {
     timeFirsAtt++;
     yoyoPower--;
     Cooldown--;
     rb.AddForce(YoyoMoove * speed * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             YoyoMoove      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         YoyoMoove      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         YoyoMoove = DirPlayer.direction / 4f;
     }
     YoyoMoove = YoyoMoove.normalized;
     if (YoyoMoove.magnitude != 0f && Cooldown < 150)
     {
         YoyoPower = YoyoMoove;
     }
     if (Cooldown <= 0)
     {
         if (YoyoMoove.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (YoyoMoove.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
     }
     if (directionChosen)
     {
         directionChosen    = false;
         yoyoPower          = 30;
         Cooldown           = 200;
         ImageIsReady.color = new Color(1f, 1f, 1f);
         rb.constraints     = RigidbodyConstraints2D.FreezeRotation;
     }
     if (Cooldown > 130)
     {
         if (AvantArriere)
         {
             HingeJoint2D jointManche = JointManche;
             Vector2      anchor      = JointManche.anchor;
             jointManche.anchor = new Vector2(0f, anchor.y - NewAnchorSpeed / 1.5f);
             avant = false;
         }
         else
         {
             HingeJoint2D jointManche2 = JointManche;
             Vector2      anchor2      = JointManche.anchor;
             jointManche2.anchor = new Vector2(0f, anchor2.y + NewAnchorSpeed);
             rb.AddForce(YoyoPower * 5f * speed * Time.fixedDeltaTime);
             if (!avant)
             {
                 source.PlayOneShot(PowerAbility);
                 avant = true;
             }
         }
         Vector2 anchor3 = JointManche.anchor;
         if (anchor3.y > 0.65f)
         {
             AvantArriere = true;
         }
         Vector2 anchor4 = JointManche.anchor;
         if (anchor4.y < -0.1f)
         {
             AvantArriere = false;
         }
     }
     if (Cooldown == 130)
     {
         JointManche.anchor = new Vector2(0f, -0.1f);
         rb.constraints     = RigidbodyConstraints2D.None;
     }
     if (Cooldown <= 0)
     {
         if (IsBlue)
         {
             ImageIsReady.color = new Color(0f, 1f, 1f);
         }
         else
         {
             ImageIsReady.color = new Color(1f, 1f, 0f);
         }
     }
 }
Ejemplo n.º 27
0
 private void FixedUpdate()
 {
     timeFirsAtt++;
     yoyoPower--;
     Cooldown--;
     rb.AddForce(YoyoMoove * speed * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             YoyoMoove      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             YoyoMoove      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         YoyoMoove      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         YoyoMoove = DirPlayer.direction / 4f;
     }
     YoyoMoove = YoyoMoove.normalized;
     if (YoyoMoove.magnitude != 0f && Cooldown < 150)
     {
         YoyoPower = YoyoMoove;
     }
     if (Cooldown <= 0)
     {
         if (YoyoMoove.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (YoyoMoove.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
     }
     if (directionChosen)
     {
         ParticleSystem.MainModule main = TrailBaguette.main;
         main.startColor = new Color(1f, 1f, 1f, 0f);
         directionChosen = false;
         Encre.SetActive(value: false);
         Encre.transform.position = base.transform.position;
         Encre.transform.rotation = base.transform.rotation;
         Encre.SetActive(value: true);
         Encre.GetComponent <Rigidbody2D>().AddForce(YoyoPower * 140f, ForceMode2D.Impulse);
         yoyoPower          = 30;
         Cooldown           = 225;
         ImageIsReady.color = new Color(1f, 1f, 1f);
         source.PlayOneShot(PowerAbility, 0.5f);
     }
     if (Cooldown <= 0)
     {
         if (IsBlue)
         {
             ParticleSystem.MainModule main1 = TrailBaguette.main;
             main1.startColor   = new Color(0f, 1f, 1f, 1f);
             ImageIsReady.color = new Color(0f, 1f, 1f);
         }
         else
         {
             ParticleSystem.MainModule main2 = TrailBaguette.main;
             main2.startColor   = new Color(1f, 1f, 0f, 1f);
             ImageIsReady.color = new Color(1f, 1f, 0f);
         }
     }
 }
Ejemplo n.º 28
0
    private void FixedUpdate()
    {
        CoolDownShoot++;
        Cooldown--;
        timeFirsAtt++;
        if (Cooldown > 220)
        {
            rb.MovePosition(rb.position + Power * speed * Time.fixedDeltaTime);
        }
        else
        {
            rb.constraints = RigidbodyConstraints2D.None;
        }
        if (!PlayerOneOrTwo)
        {
            if (!SkinChoose.OnePlayer)
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
            else if (!SkinChoose.LeftUser)
            {
                direction      = rightJoystick.GetInputDirection();
                JoystickOnZero = rightJoystick.IsTouching;
            }
            else
            {
                direction      = leftJoystick.GetInputDirection();
                JoystickOnZero = leftJoystick.IsTouching;
            }
        }
        else if (!DirPlayer.AI)
        {
            direction      = rightJoystick.GetInputDirection();
            JoystickOnZero = rightJoystick.IsTouching;
        }
        else
        {
            direction = DirPlayer.direction / 4f;
        }
        direction = direction.normalized;
        rb.AddForce(direction * maniment * Time.fixedDeltaTime);
        if (direction.magnitude != 0f)
        {
            Power = direction;
        }
        if (Cooldown <= 0)
        {
            if (!PlayerOneOrTwo)
            {
                gunsprite.color = new Color(0f, 0.7f, 1f);
            }
            else
            {
                gunsprite.color = new Color(1f, 0f, 0f);
            }
            if (direction.magnitude > 0.2f && timeFirsAtt > 100)
            {
                PowerhitReady = true;
            }
            if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
            {
                directionChosen = true;
                PowerhitReady   = false;
            }
        }
        else
        {
            gunsprite.color = new Color(0f, 0f, 0f);
        }
        if (directionChosen)
        {
            source.PlayOneShot(PowerAbilityBigShot);
            Cooldown        = 190;
            directionChosen = false;
            SuperBullet.transform.position = base.transform.position;
            SuperBullet.transform.rotation = base.transform.rotation;
            SuperBullet.SetActive(value: true);
            BulletSpeed.y = Speed;
            SuperBullet.GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed * 1.5f, ForceMode2D.Impulse);
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            rb.MovePosition(rb.position + Power * speed * Time.fixedDeltaTime);
            SuperBullet1.transform.position = base.transform.position;
            SuperBullet1.transform.rotation = base.transform.rotation;
            SuperBullet1.transform.Rotate(0f, 0f, 10f, Space.Self);
            SuperBullet1.SetActive(value: true);
            SuperBullet1.GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed * 1.5f, ForceMode2D.Impulse);
            SuperBullet2.transform.position = base.transform.position;
            SuperBullet2.transform.rotation = base.transform.rotation;
            SuperBullet2.transform.Rotate(0f, 0f, -10f, Space.Self);
            SuperBullet2.SetActive(value: true);
            SuperBullet2.GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed * 1.5f, ForceMode2D.Impulse);
        }
        if (ReloadTime > 0)
        {
            ReloadTime--;
        }
        if (timeFirsAtt <= 100 || direction.magnitude == 0f || ReloadTime >= 1 || CoolDownShoot < 40)
        {
            return;
        }
        CoolDownShoot = 0;
        int num = 0;

        while (true)
        {
            if (num < arrow.Length)
            {
                if (!arrow[num].activeInHierarchy)
                {
                    break;
                }
                num++;
                continue;
            }
            return;
        }
        source.PlayOneShot(PowerAbility);
        ShootNumber++;
        if (ShootNumber >= 4)
        {
            ReloadTime  = 110;
            ShootNumber = 0;
            Fumer.SetActive(value: true);
        }
        arrow[num].transform.position = base.transform.position;
        arrow[num].transform.rotation = base.transform.rotation;
        arrow[num].SetActive(value: true);
        BulletSpeed.y = Speed;
        arrow[num].GetComponent <Rigidbody2D>().AddRelativeForce(BulletSpeed, ForceMode2D.Impulse);
        rb.MovePosition(rb.position + Power * speed / 2f * Time.fixedDeltaTime);
    }
    void FixedUpdate()
    {
        // get input from both joysticks
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

        float xMovementLeftJoystick = leftJoystickInput.x;   // The horizontal movement from joystick 01
        float zMovementLeftJoystick = leftJoystickInput.y;   // The vertical movement from joystick 01

        float xMovementRightJoystick = rightJoystickInput.x; // The horizontal movement from joystick 02
        float zMovementRightJoystick = rightJoystickInput.y; // The vertical movement from joystick 02

        // if there is no input on the left joystick
        if (leftJoystickInput == Vector3.zero)
        {
            animator.SetBool("isRunning", false);
        }
        // if there is no input on the right joystick
        if (rightJoystickInput == Vector3.zero)
        {
            animator.SetBool("isAttacking", false);
        }

        // if there is only input from the left joystick
        if (leftJoystickInput != Vector3.zero && rightJoystickInput == Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngle = Mathf.Atan2(zMovementLeftJoystick, xMovementLeftJoystick);
            xMovementLeftJoystick *= Mathf.Abs(Mathf.Cos(tempAngle));
            zMovementLeftJoystick *= Mathf.Abs(Mathf.Sin(tempAngle));

            leftJoystickInput  = new Vector3(xMovementLeftJoystick, 0, zMovementLeftJoystick);
            leftJoystickInput  = transform.TransformDirection(leftJoystickInput);
            leftJoystickInput *= moveSpeed;

            // rotate the player to face the direction of input
            Vector3 temp = transform.position;
            temp.x += xMovementLeftJoystick;
            temp.z += zMovementLeftJoystick;
            Vector3 lookDirection = temp - transform.position;
            if (lookDirection != Vector3.zero)
            {
                rotationTarget.localRotation = Quaternion.Slerp(rotationTarget.localRotation, Quaternion.LookRotation(lookDirection), rotationSpeed * Time.deltaTime);
            }
            if (animator != null)
            {
                animator.SetBool("isRunning", true);
            }

            // move the player
            rigidBody.transform.Translate(leftJoystickInput * Time.fixedDeltaTime);
        }

        // if there is only input from the right joystick
        if (leftJoystickInput == Vector3.zero && rightJoystickInput != Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngle = Mathf.Atan2(zMovementRightJoystick, xMovementRightJoystick);
            xMovementRightJoystick *= Mathf.Abs(Mathf.Cos(tempAngle));
            zMovementRightJoystick *= Mathf.Abs(Mathf.Sin(tempAngle));

            // rotate the player to face the direction of input
            Vector3 temp = transform.position;
            temp.x += xMovementRightJoystick;
            temp.z += zMovementRightJoystick;
            Vector3 lookDirection = temp - transform.position;
            if (lookDirection != Vector3.zero)
            {
                rotationTarget.localRotation = Quaternion.Slerp(rotationTarget.localRotation, Quaternion.LookRotation(lookDirection) * Quaternion.Euler(0, 45f, 0), rotationSpeed * Time.deltaTime);
            }

            animator.SetBool("isAttacking", true);
        }

        // if there is input from both joysticks (Left And Right)
        if (leftJoystickInput != Vector3.zero && rightJoystickInput != Vector3.zero)
        {
            // calculate the player's direction based on angle
            float tempAngleInputRightJoystick = Mathf.Atan2(zMovementRightJoystick, xMovementRightJoystick);
            xMovementRightJoystick *= Mathf.Abs(Mathf.Cos(tempAngleInputRightJoystick));
            zMovementRightJoystick *= Mathf.Abs(Mathf.Sin(tempAngleInputRightJoystick));

            // rotate the player to face the direction of input
            Vector3 temp = transform.position;
            temp.x += xMovementRightJoystick;
            temp.z += zMovementRightJoystick;
            Vector3 lookDirection = temp - transform.position;
            if (lookDirection != Vector3.zero)
            {
                rotationTarget.localRotation = Quaternion.Slerp(rotationTarget.localRotation, Quaternion.LookRotation(lookDirection) * Quaternion.Euler(0, 45f, 0), rotationSpeed * Time.deltaTime);
            }

            animator.SetBool("isAttacking", true);

            // calculate the player's direction based on angle
            float tempAngleLeftJoystick = Mathf.Atan2(zMovementLeftJoystick, xMovementLeftJoystick);
            xMovementLeftJoystick *= Mathf.Abs(Mathf.Cos(tempAngleLeftJoystick));
            zMovementLeftJoystick *= Mathf.Abs(Mathf.Sin(tempAngleLeftJoystick));

            leftJoystickInput  = new Vector3(xMovementLeftJoystick, 0, zMovementLeftJoystick);
            leftJoystickInput  = transform.TransformDirection(leftJoystickInput);
            leftJoystickInput *= moveSpeed;

            if (animator != null)
            {
                animator.SetBool("isRunning", true);
            }

            // move the player
            rigidBody.transform.Translate(leftJoystickInput * Time.fixedDeltaTime);
        }
    }
Ejemplo n.º 30
0
 private void FixedUpdate()
 {
     timeFirsAtt++;
     Cooldown--;
     rb.AddForce(direction * maniment * Time.fixedDeltaTime);
     if (!PlayerOneOrTwo)
     {
         if (!SkinChoose.OnePlayer)
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
         else if (!SkinChoose.LeftUser)
         {
             direction      = rightJoystick.GetInputDirection();
             JoystickOnZero = rightJoystick.IsTouching;
         }
         else
         {
             direction      = leftJoystick.GetInputDirection();
             JoystickOnZero = leftJoystick.IsTouching;
         }
     }
     else if (!DirPlayer.AI)
     {
         direction      = rightJoystick.GetInputDirection();
         JoystickOnZero = rightJoystick.IsTouching;
     }
     else
     {
         direction = DirPlayer.direction / 4f;
     }
     direction = direction.normalized;
     if (direction.magnitude != 0f)
     {
         Power = direction;
     }
     if (Cooldown <= 0)
     {
         if (Cooldown == 0)
         {
             StatePower = UnityEngine.Random.Range(0, 3);
             Logo.SetActive(value: true);
             if (StatePower == 0)
             {
                 TntLogo.SetActive(value: true);
             }
             if (StatePower == 1)
             {
                 RockLogo.SetActive(value: true);
             }
             if (StatePower == 2)
             {
                 PistonLogo.SetActive(value: true);
             }
         }
         if (direction.magnitude > 0.2f && timeFirsAtt > 100)
         {
             PowerhitReady = true;
         }
         if (direction.magnitude == 0f && PowerhitReady && !JoystickOnZero)
         {
             directionChosen = true;
             PowerhitReady   = false;
         }
         symboleUlt.GetComponent <SpriteRenderer>().enabled = false;
     }
     if (directionChosen)
     {
         source.PlayOneShot(PowerAbility);
         Cooldown        = 150;
         directionChosen = false;
         Logo.SetActive(value: false);
         if (StatePower == 0)
         {
             Tnt.gameObject.SetActive(value: false);
             Tnt.transform.position = base.transform.position;
             Tnt.gameObject.SetActive(value: true);
             Tnt.GetComponent <Rigidbody2D>().AddForce(Power * 4f, ForceMode2D.Impulse);
             TntLogo.SetActive(value: false);
         }
         if (StatePower == 1)
         {
             Rock.gameObject.SetActive(value: false);
             Rock.transform.position = base.transform.position;
             Rock.transform.rotation = base.transform.rotation;
             Rock.transform.Translate(-2f, 0f, 0f, Space.Self);
             Rock.transform.rotation = new Quaternion(0f, 0f, 0f, 1f);
             Rock.gameObject.SetActive(value: true);
             RockLogo.SetActive(value: false);
         }
         if (StatePower == 2)
         {
             Piston.gameObject.SetActive(value: false);
             Piston.transform.position = base.transform.position;
             Piston.transform.rotation = base.transform.rotation;
             Piston.transform.Translate(-2f, 0f, 0f, Space.Self);
             Piston.transform.Rotate(0f, 0f, 180f, Space.Self);
             Piston.gameObject.SetActive(value: true);
             PistonLogo.SetActive(value: false);
         }
         symboleUlt.GetComponent <SpriteRenderer>().enabled = true;
     }
 }