Ejemplo n.º 1
0
    public void MovingControllerUpdate()
    {
        Vector2 p = leftJoyStick.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.Move(leftJoyStick.GetInputDirection(), Quaternion.AngleAxis(angle, Vector3.forward));
    }
Ejemplo n.º 2
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.º 3
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.º 4
0
    void Update()
    {
        // get input from both joysticks
        leftJoystickInput = leftJoystick.GetInputDirection();

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

        // 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));

            leftJoystickInput  = new Vector3(xMovementLeftJoystick, 0, zMovementLeftJoystick);
            leftJoystickInput  = transform.TransformDirection(leftJoystickInput);
            leftJoystickInput *= moveSpeed;
            if (!Physics.Raycast(transform.position, leftJoystickInput, 14f, layerMask))
            {
                transform.Translate(leftJoystickInput * moveSpeed * Time.deltaTime, Space.World);
            }


            // move the player
            //rigidBody.transform.Translate(leftJoystickInput * Time.fixedDeltaTime);
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        float x    = Input.GetAxisRaw("Horizontal");
        float y    = Input.GetAxisRaw("Vertical");
        float coef = 1f;

        if (controller != null && controller.isActiveAndEnabled)
        {
            Vector3 dir = controller.GetInputDirection();
            x    = dir.x;
            y    = dir.y;
            coef = 0.6f;
        }

        Vector2 direction = new Vector2(x, y).normalized;

        GetComponent <Rigidbody2D>().velocity = direction * speed * coef;

        if (Input.GetButtonDown("Fire1"))
        {
            Fire(bullet);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(prefabMeteo, Vector3.zero, Quaternion.identity);
        }
    }
Ejemplo n.º 6
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.º 7
0
    private Vector3 HandleJoystickMove()
    {
        var leftJoystickInput = leftJoystickController.GetInputDirection();
        var leftJoystickMove  = new Vector3(-leftJoystickInput.y, 0, -leftJoystickInput.x);

        return(leftJoystickMove.normalized);
    }
Ejemplo n.º 8
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();
        }
    }
 public Vector3 GetInput()
 {
     if (joystick == null)
     {
         return(Vector3.zero);
     }
     return(joystick.GetInputDirection());;
 }
Ejemplo n.º 10
0
    private void GetInputs()
    {
        leftJoystickInput  = leftJoystick.GetInputDirection();
        rightJoystickInput = rightJoystick.GetInputDirection();

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

        rightJoystickX = rightJoystickInput.x;
        rightJoytsickY = rightJoystickInput.y;
    }
Ejemplo n.º 11
0
    private void handleMovement()
    {
        if (leftJoystick != null)
        {
            Vector3 moveVector   = leftJoystick.GetInputDirection();
            Vector3 moveInput    = new Vector3(moveVector.x, 0, moveVector.y);
            Vector3 moveVelocity = moveInput.normalized * moveSpeed;

            controller.Move(moveVelocity);
        }
    }
Ejemplo n.º 12
0
    void FixedUpdate()
    {
        if (canMove)
        {
            // get input from both joysticks
            leftJoystickInput = leftJoystick.GetInputDirection();

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

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

            // 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));

                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
                navMeshAgent.Move(leftJoystickInput * Time.fixedDeltaTime);
            }
        }
    }
    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.º 14
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // get input from both joysticks
        leftJoystickInput = leftJoystick.GetInputDirection();

        float xMovementLeftJoystick = leftJoystickInput.y + leftJoystickInput.x; // The horizontal movement from joystick 01, mapped to angle
        float zMovementLeftJoystick = leftJoystickInput.y - leftJoystickInput.x; // The vertical movement from joystick 01, mapped to angle

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

        // 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));

            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 (animator != null)
            {
                animator.SetBool("isRunning", true);
            }

            // move the player
            rigidBody.transform.Translate(leftJoystickInput * Time.fixedDeltaTime);
        }
    }
Ejemplo n.º 15
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.º 16
0
    public void MovCam()
    {
        leftJoystickInput = leftJoystick.GetInputDirection();

        posJoistyckX += leftJoystickInput.x * secibility * Time.deltaTime;
        posJoistyckY -= leftJoystickInput.y * secibility * Time.deltaTime;

        if (posJoistyckY <= limiteYp.y)
        {
            valorLimite = limiteYp.y;
        }
        else if (posJoistyckY >= limiteYn.y)
        {
            valorLimite = limiteYn.y;
        }
        else
        {
            valorLimite = posJoistyckY;
        }

        transform.eulerAngles = new Vector3(valorLimite, posJoistyckX, 0);
    }
Ejemplo n.º 17
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.º 18
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.º 20
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.º 21
0
    // Update is called once per frame
    void Update()
    {
        step = changespeed * Time.deltaTime;

        //myRigidBody.velocity = new Vector3(moveSpeed, myRigidBody.velocity.y, 0f);
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
        //player.transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime);
        jumpTime   -= Time.deltaTime;
        groundTime -= Time.deltaTime;

        if (knockBackCounter > 0)
        {
            knockBackCounter -= Time.deltaTime;

            if (transform.localScale.x > 0)
            {
                myRigidBody.velocity = new Vector3(-knockBackForce, knockBackForce, 0f);
            }
            else
            {
                myRigidBody.velocity = new Vector3(knockBackForce, knockBackForce, 0f);
            }
        }

        if (invincibilityCounter > 0)
        {
            invincibilityCounter -= Time.deltaTime;
        }


        if (invincibilityCounter <= 0)
        {
            theLevelManager.invincible = false;
        }


        myAnim.SetFloat("Speed", Mathf.Abs(myRigidBody.velocity.x));
        myAnim.SetFloat("JumpSpeed", myRigidBody.velocity.y);
        myAnim.SetBool("Grounded", isGrounded);

        if (myRigidBody.velocity.y < 0)
        {
            stompBox.SetActive(true);
        }
        else
        {
            stompBox.SetActive(false);
        }

        if (joystick == true)
        {
            leftJoystickInput = leftJoystick.GetInputDirection();
        }


        if (isGrounded == true)
        {
            groundTime = groundGrace;
            jsound     = true;
        }
        if (isGrounded == false)
        {
            jsound = false;
        }

        if (knockBackCounter <= 0 && canMove)
        {
            if (redbird == true)
            {
                transform.Translate(Input.acceleration.x, 0, 0);
            }

            if (joystick == true)
            {
                if (leftJoystickInput.x > 0)
                {
                    myRigidBody.velocity = new Vector3(moveSpeed, myRigidBody.velocity.y, 0f);
                    if (shrunk == false)
                    {
                        transform.localScale = new Vector3(1f, 1f, 1f);
                    }

                    else if (shrunk == true)
                    {
                        transform.localScale = new Vector3(.5f, .5f, .5f);
                    }
                }
                if (leftJoystickInput.x < 0)
                {
                    myRigidBody.velocity = new Vector3(-moveSpeed, myRigidBody.velocity.y, 0f);
                    if (shrunk == false)
                    {
                        transform.localScale = new Vector3(-1f, 1f, 1f);
                    }

                    else if (shrunk == true)
                    {
                        transform.localScale = new Vector3(-.5f, .5f, .5f);
                    }
                }
                if (leftJoystickInput.x == 0)
                {
                    myRigidBody.velocity = new Vector3(0f, myRigidBody.velocity.y, 0f);
                }
            }

            if (Input.GetAxisRaw("Horizontal") > 0f)
            {
                //transform.localScale = new Vector3 (1f, 1f, 1f);
                myRigidBody.velocity = new Vector3(moveSpeed, myRigidBody.velocity.y, 0f);
                if (shrunk == false)
                {
                    transform.localScale = new Vector3(1f, 1f, 1f);
                }

                else if (shrunk == true)
                {
                    transform.localScale = new Vector3(.5f, .5f, .5f);
                }
            }
            else if (Input.GetAxisRaw("Horizontal") < 0f)
            {
                //transform.localScale = new Vector3 (-1f, 1f, 1f);
                myRigidBody.velocity = new Vector3(-moveSpeed, myRigidBody.velocity.y, 0f);
                if (shrunk == false)
                {
                    transform.localScale = new Vector3(-1f, 1f, 1f);
                }

                else if (shrunk == true)
                {
                    transform.localScale = new Vector3(-.5f, .5f, .5f);
                }
            }
            //else

            //{
            // myRigidBody.velocity = new Vector3(0f, myRigidBody.velocity.y, 0f);
            //}


            if (Input.GetButtonDown("Jump")) //&& isGrounded)
            {
                jumpTime = jumpGrace;

                //myRigidBody.velocity = new Vector3 (myRigidBody.velocity.x, jumpSpeed, 0f);
                if (jsound == true)
                {
                    jumpSound.Play();
                    jsound = false;
                }
            }

            if (jumpTime > 0 && groundTime > 0)
            {
                myRigidBody.velocity = new Vector3(myRigidBody.velocity.x, jumpSpeed, 0f);
                //jumpSound.Play ();
            }

            if (joypad == true)
            {
                if (CnInputManager.GetAxisRaw("Horizontal") > 0f)
                {
                    transform.localScale = new Vector3(1f, 1f, 1f);
                    myRigidBody.velocity = new Vector3(moveSpeed, myRigidBody.velocity.y, 0f);
                    if (shrunk == false)
                    {
                        transform.localScale = new Vector3(1f, 1f, 1f);
                    }

                    else if (shrunk == true)
                    {
                        transform.localScale = new Vector3(.5f, .5f, .5f);
                    }
                }
                else if (CnInputManager.GetAxisRaw("Horizontal") < 0f)
                {
                    transform.localScale = new Vector3(-1f, 1f, 1f);
                    myRigidBody.velocity = new Vector3(-moveSpeed, myRigidBody.velocity.y, 0f);
                    if (shrunk == false)
                    {
                        transform.localScale = new Vector3(-1f, 1f, 1f);
                    }

                    else if (shrunk == true)
                    {
                        transform.localScale = new Vector3(-.5f, .5f, .5f);
                    }
                }
                else
                {
                    myRigidBody.velocity = new Vector3(0f, myRigidBody.velocity.y, 0f);
                }
            }

            if (CnInputManager.GetButtonDown("Jump")) //&& isGrounded)
            {
                jumpTime = jumpGrace;
                //myRigidBody.velocity = new Vector3(myRigidBody.velocity.x, jumpSpeed, 0f);
                if (jsound == true)
                {
                    jumpSound.Play();
                }
                //jumpSound.Play();
            }
        }
    }
Ejemplo n.º 22
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);
    }
Ejemplo n.º 23
0
    // Update is called once per frame
    void Update()
    {
        if (!PV.IsMine)
        {
            return;
        }
        if (EM.countOfCurrentElectrons == 0)
        {
            Instantiate(GameOverUI, transform.position, Quaternion.identity);
            PhotonNetwork.Instantiate("Explode", transform.position, Quaternion.identity);
            PhotonNetwork.Destroy(gameObject);
        }
        // rb.AddForce(new Vector3(Input.GetAxis("Vertical") * speed,0, Input.GetAxis("Horizontal") * speed));
        //rb.AddForce(Camera.main.transform.forward* Input.GetAxis("Vertical")*speed);
        //rb.AddForce(Camera.main.transform.forward * Input.GetAxis("Horizontal") * speed);
        float ystore = targetDirection.y;

        //targetDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
        if (mobileSupport)
        {
            targetDirection = new Vector3(LJ.GetInputDirection().x, 0f, LJ.GetInputDirection().y);
        }
        else
        {
            targetDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
        }
        targetDirection   = Camera.transform.GetChild(0).TransformDirection(targetDirection);
        targetDirection.y = ystore;
        if (controller.isGrounded)
        {
            targetDirection.y = 0f;
        }
        targetDirection.y = targetDirection.y + (Physics.gravity.y * gravityScale);
        controller.Move(targetDirection * speed * Time.deltaTime);
        // rb.AddForce(Input.GetAxis("Vertical") * speed, 0, Input.GetAxis("Vertical") * speed);
        //rb.AddForce(Input.GetAxis("Horizontal") * speed, 0, -Input.GetAxis("Horizontal") * speed);
        // print(Camera.main.transform.forward);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            Ray        ray = Camera.transform.GetChild(0).GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                //draw invisible ray cast/vector
                Debug.DrawLine(ray.origin, hit.point);
                //log hit area to the console
                //Debug.Log(hit.point);
                if (!Input.GetKey(KeyCode.Mouse1))
                {
                    if (CanBullet1 == true && !Input.GetKey(KeyCode.Space))
                    {
                        GameObject b = PhotonNetwork.Instantiate("Bullet", transform.position, Quaternion.identity);
                        b.transform.GetChild(0).GetComponent <BulletScript>().hitPointRPC(hit.point);

                        CanBullet1 = false;
                        CanBullet2 = false;
                        foreach (var item in co)
                        {
                            StopCoroutine(item);
                        }
                        co.Add(StartCoroutine(check()));
                    }
                    else if (CanBullet2 == true && Input.GetKey(KeyCode.Space))
                    {
                        GameObject b = PhotonNetwork.Instantiate("Bullet2", transform.position, Quaternion.identity);
                        b.transform.GetChild(0).GetComponent <BulletScript>().hitPointRPC(hit.point);

                        Camera.GetComponent <CameraFollow>().RemoveALightning();
                        Camera.GetComponent <CameraFollow>().LightningAnim.SetTrigger("Shake");
                        CanBullet1 = false;
                        CanBullet2 = false;
                        foreach (var item in co)
                        {
                            StopCoroutine(item);
                        }
                        co.Add(StartCoroutine(check()));
                    }
                    //PV.RPC("RPCBulletVars", RpcTarget.All, b, gameObject, hit.point);
                    //b.transform.GetChild(0).GetComponent<BulletScript>().owner = gameObject;
                    //b.transform.GetChild(0).GetComponent<BulletScript>().lookPoint = hit.point;
                    //rb.AddForce(hit.point * bulletSpeed);
                    // b.transform.GetChild(0).GetComponent<Rigidbody>().velocity = hit.point;
                }
            }
        }
        bool yes = false;

        foreach (var item in Camera.GetComponent <CameraFollow>().lightningScripts)
        {
            if (item.CurrentNumOfPoints == 0)
            {
                yes = true;
            }
        }
        if (yes == true)
        {
            CanBullet2 = true;
        }
        else
        {
            CanBullet2 = false;
        }
    }
Ejemplo n.º 24
0
    // Update is called once per frame
    void Update()
    {
        moveDirection = Vector3.zero;

        /**
         #if UNITY_STANDALONE || UNITY_WEBPLAYER
         * moveHorizontal = Input.GetAxis("Horizontal");
         * moveVertical = Input.GetAxis("Vertical");
         *
         * Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         * if (!Physics.Raycast(transform.position, movement, 14f, layerMask))
         * {
         *  transform.Translate(movement * movementSpeed * Time.deltaTime, Space.World);
         * }
         * if (Input.GetKeyDown(KeyCode.Space))
         * {
         *  jump();
         * }       **/
        //#elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
        activeJoystickInput = Vector3.zero;

        if (PlayerPrefs.GetInt("swapControls") == 0)
        {
            activeJoystickInput = leftJoystick.GetInputDirection();
            moveDirection       = new Vector3(activeJoystickInput.x, 0f, activeJoystickInput.y);
            direction           = (leftJoystickHandle.localPosition - leftCentreJoystick.localPosition);
        }
        else if (PlayerPrefs.GetInt("swapControls") == 1)
        {
            activeJoystickInput = rightJoystick.GetInputDirection();
            moveDirection       = new Vector3(activeJoystickInput.x, 0f, activeJoystickInput.y);
            direction           = (rightJoystickHandle.localPosition - rightCentreJoystick.localPosition);
        }

        magnitude             = direction.magnitude / 8f;
        directionNormalized   = direction.normalized;
        directionNormalized.z = directionNormalized.y;
        directionNormalized.y = 0f;


        // if there is touch input
        if (activeJoystickInput != Vector3.zero)
        {
            // player is rotated to direction of movement
            Quaternion rotation = Quaternion.LookRotation(moveDirection, Vector3.up) * Quaternion.Euler(0f, 90f, 0f);
            transform.rotation = rotation;
            // these are used to check in a cone in front of the player.
            // this helps prevent clipping through walls.
            Vector3 leftPosition  = Quaternion.AngleAxis(-30, Vector3.up) * directionNormalized;
            Vector3 rightPosition = Quaternion.AngleAxis(30, Vector3.up) * directionNormalized;

            //COllision detection. Prevents walking through walls/planes, which is possible with
            //BoxColliders
            if (!Physics.Raycast(transform.position, leftPosition, 1.3f, layerMask) &&
                !Physics.Raycast(transform.position, rightPosition, 1.3f, layerMask))
            {
                transform.Translate(directionNormalized * magnitude * movementSpeed * Time.deltaTime, Space.World);
            }

            //if (transform.position.x < corner1.x - .5f && transform.position.x > corner2.x + .5f && transform.position.z < corner1.z - .5f && transform.position.z > corner2.z + .5f)
            //{
            //}
        }
        //#endif
    }
Ejemplo n.º 25
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.º 26
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.º 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()
 {
     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.º 29
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.º 30
0
    private void FixedUpdate()
    {
        healthBar.localScale = new Vector3(((float)health / (float)maxHealth), 1, 1);

        playerRot = new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z);
        PlayerAnimator.SetBool("Grounded", grounded);

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

        if (health <= 0)
        {
            healthBar.localScale = new Vector3(0, 1, 1);
            GameObject.Find("CameraBox").GetComponent <CameraPusher>().enabled = false;
            StartCoroutine(Die());
        }

        if (Input.GetKey(KeyCode.Space))
        {
            Jump();
        }



        if (leftJoystickInput != Vector3.zero && movementAllowed)
        {
            moving = true;
            Vector3 joystickXOnly = new Vector3(leftJoystickInput.x, 0.0f, 0.0f);
            moveMagnitude = leftJoystickInput.x;

            if (moveMagnitude < 0)
            {
                moveMagnitude = moveMagnitude * -1;
            }

            if (leftJoystickInput.x > 0)
            {
                looking = 1;
            }
            else
            if (leftJoystickInput.x < 0)
            {
                looking = -1;
            }

            if (climbingStairs)
            {
                PlayerAnimator.SetFloat("Forward", moveMagnitude * 0.8f, 0.2f, Time.deltaTime);
            }
            else
            {
                PlayerAnimator.SetFloat("Forward", moveMagnitude, 0.2f, Time.deltaTime);
            }

            if (!grounded)
            {
                GetComponent <Rigidbody>().velocity = new Vector3(GetComponent <Rigidbody>().velocity.x + (looking * 0.05f), GetComponent <Rigidbody>().velocity.y, 0);
            }
            else
            {
                GetComponent <Rigidbody>().velocity = new Vector3(leftJoystickInput.x * movespeedMod, GetComponent <Rigidbody>().velocity.y, 0);
            }
        }
        else
        if (Input.GetAxis("Horizontal") != 0 && movementAllowed)
        {
            moving = true;
            Vector3 joystickXOnly = new Vector3(Input.GetAxis("Horizontal"), 0.0f, 0.0f);
            moveMagnitude = Input.GetAxis("Horizontal");

            if (moveMagnitude < 0)
            {
                moveMagnitude = moveMagnitude * -1;
            }

            if (Input.GetAxis("Horizontal") > 0)
            {
                looking = 1;
            }
            else
            if (Input.GetAxis("Horizontal") < 0)
            {
                looking = -1;
            }

            if (climbingStairs)
            {
                PlayerAnimator.SetFloat("Forward", moveMagnitude * 0.8f, 0.2f, Time.deltaTime);
            }
            else
            {
                PlayerAnimator.SetFloat("Forward", moveMagnitude, 0.2f, Time.deltaTime);
            }

            if (!grounded)
            {
                GetComponent <Rigidbody>().velocity = new Vector3(GetComponent <Rigidbody>().velocity.x + (looking * 0.05f), GetComponent <Rigidbody>().velocity.y, 0);
            }
            else
            {
                GetComponent <Rigidbody>().velocity = new Vector3(Input.GetAxis("Horizontal") * movespeedMod, GetComponent <Rigidbody>().velocity.y, 0);
            }
        }
        else
        {
            GetComponent <Rigidbody>().velocity = new Vector3(0, GetComponent <Rigidbody>().velocity.y, 0);
            moving = false;
            PlayerAnimator.SetFloat("Forward", 0.0f, 0.2f, Time.deltaTime);
        }

        if (looking == -1 && transform.rotation.eulerAngles.y != 270.0f)
        {
            var desiredRotQ = Quaternion.Euler(transform.eulerAngles.x, 270.0f, transform.eulerAngles.z);
            transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotQ, Time.deltaTime * 10f);
        }
        else
        if (looking == 1 && transform.rotation.eulerAngles.y != 90.0f)
        {
            var desiredRotQ = Quaternion.Euler(transform.eulerAngles.x, 90.0f, transform.eulerAngles.z);
            transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotQ, Time.deltaTime * 10f);
        }


        if (transform.position.z != forcedZPos)
        {
            Vector3 NewPos = new Vector3(transform.position.x, transform.position.y, forcedZPos);
            transform.position = NewPos;
        }

        if (leftJoystickInput.y <= -0.8 && movementAllowed)
        {
            PlayerAnimator.SetBool("Crouched", true);
        }
        else
        {
            PlayerAnimator.SetBool("Crouched", false);
        }

        if (wepactive)
        {
            if (SpeedGetRunning == false)
            {
                StartCoroutine(SpeedandDistance());
            }

            //weapon.transform.position = weppos.transform.position;
        }

        if (!grounded && !falling)
        {
            StartCoroutine(Falling());
        }

        if (grounded)
        {
            StopCoroutine(Falling());
        }
    }