//Movment method

    private void CharacterMove()
    {
        //moving on the plane
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal() * moveSpeed;
        //moveVector.z = mContr.Vertical()*moveSpeed*(-1);  //THIS ROW IS FOR NORMAL MODE
        moveVector.z = mContr.Vertical() * moveSpeed; //THIS ROW IS FOR SPEEDRUN MODE

        //Movement animaion

        if (ch_controller.isGrounded && (moveVector.x != 0 || moveVector.z != 0))
        {
            ch_animator.SetBool("Run", true);
        }
        else
        {
            ch_animator.SetBool("Run", false);
        }


        //Rotation

        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, moveSpeed, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime);
    }
Exemple #2
0
    //Метод перемещения персонажа
    private void CharacterMove()
    {
        //Перемещение по поверхности
        moveVector   = Vector3.zero;
        moveVector.x = mController.Horizontal() * speed;
        moveVector.z = mController.Vertical() * speed;

        //Анимация передвижения персонажа
        if (moveVector.x != 0 || moveVector.z != 0)
        {
            ch_animator.SetBool("walk", true);
        }
        else
        {
            ch_animator.SetBool("walk", false);
        }

        //Поворот персонажа в сторону направления перемещения
        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speed, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime);
    }
Exemple #3
0
    //метод перемещения персонажа
    private void CharacterMove()
    {
        //перемещение по поверхности
        moveVector   = Vector3.zero;
        moveVector.z = /*Input.GetAxis("Vertical")*/ mContr.Vertical() * speedMove;
        moveVector.x = /*Input.GetAxis("Horizontal")*/ mContr.Horizontal() * speedMove;

        //анимация передвижения персонажа
        if ((moveVector.x != 0 || moveVector.z != 0) && ch_controller.isGrounded)
        {
            ch_animator.SetBool("run", true);
        }
        else
        {
            ch_animator.SetBool("run", false);
        }


        //поворот в сторону движения
        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime); //метод передвижения по направлению
    }
Exemple #4
0
    private void CharacterMove()
    {
        direction   = Vector3.zero;
        direction.x = mContr.Horizontal() * speed;
        direction.z = mContr.Vertical() * speed;



        if ((direction.x != 0 || direction.z != 0) && (Mathf.Abs(direction.x) + Mathf.Abs(direction.z) < 3) && (Mathf.Abs(direction.x) + Mathf.Abs(direction.z) > -3))
        {
            ch_animator.SetBool("Walk", true);
            ch_animator.SetBool("Run", false);
        }
        else if ((direction.x != 0 || direction.z != 0) && (Mathf.Abs(direction.x) + Mathf.Abs(direction.z) > 3) || (Mathf.Abs(direction.x) + Mathf.Abs(direction.z) < -3))
        {
            ch_animator.SetBool("Walk", false);
            ch_animator.SetBool("Run", true);
        }
        else
        {
            ch_animator.SetBool("Walk", false); ch_animator.SetBool("Run", false);
        }

        if (Vector3.Angle(Vector3.forward, direction) > 1f || Vector3.Angle(Vector3.forward, direction) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, direction, speed, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        direction.y = gravity;
        ch_controller.Move(direction * Time.deltaTime);
    }
Exemple #5
0
    private void Update()
    {
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal();
        moveVector.y = mContr.Vertical();
        Debug.Log("Pos x: " + moveVector.x);
        Debug.Log("Pos y: " + moveVector.y);
        if (moveVector.x > 0.9)
        {
            animator.Play("Move_right");
        }
        else if (moveVector.x < -0.9)
        {
            animator.Play("Move_left");
        }
        else
        {
            if (moveVector.y > 0)
            {
                animator.Play("Move_back");
            }
            else if (moveVector.y < 0)
            {
                animator.Play("Move_face");
            }
            else
            {
                animator.Play("Idle_right");
            }
        }

        var moveInput = new Vector2(moveVector.x, moveVector.y);

        moveVelocity = moveInput * playerSpeed;
    }
    private void CharacterMove()
    {
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal() * speedMove;
        moveVector.z = mContr.Vertical() * speedMove;

        moveVector.y = gravityForce;

        ch_controller.Move(moveVector * Time.deltaTime);
    }
Exemple #7
0
    public void CamerOsy()
    {
        // float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
        // float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;

        float      tiltAroundZ = mContr.Horizontal() * tiltAngle;
        float      tiltAroundX = mContr.Vertical() * tiltAngle;
        Quaternion target      = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);

        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
    }
Exemple #8
0
    private void CharacterMove()
    {
        moveVector   = Vector3.zero; //обнуление во избежание ошибок
        moveVector.x = mContr.Horizontal() * speedMove;
        moveVector.z = mContr.Vertical() * speedMove;

        //поворот персонажа в сторону направления перемещения
        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        player_controller.Move(moveVector * Time.deltaTime); //метод передвижения по направлению
    }
Exemple #9
0
    private void CharacterMove()
    {
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal() * speedMove;
        moveVector.z = mContr.Vertical() * speedMove;



        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }
        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime);
    }
    private void CharacterMove()
    {
        if (chController.isGrounded)
        {
            chAnimator.ResetTrigger("Jump");
            chAnimator.SetBool("Falling", false);

            moveVector = Vector3.zero;


            //if android && !unity editor
            moveVector.x = mContr.Horizontal() * speedMove;
            moveVector.z = mContr.Vertical() * speedMove;

            //else
            //moveVector.x = Input.GetAxis("Horizontal") * speedMove;
            //moveVector.z = Input.GetAxis("Vertical") * speedMove;

            //анимация ходьбы
            if (moveVector.x != 0 || moveVector.z != 0)
            {
                chAnimator.SetBool("Move", true);
            }
            else
            {
                chAnimator.SetBool("Move", false);
            }

            //поворот
            if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
            {
                Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
                transform.rotation = Quaternion.LookRotation(direct);
            }
        }
        else
        {
            if (gravityForce < -1.1f)
            {
                chAnimator.SetBool("Falling", true);
            }
        }

        moveVector.y = gravityForce;
        chController.Move(moveVector * Time.deltaTime);
    }
    /// <summary>
    /// Метод перемещения персонажа.
    /// </summary>
    private void PlayerMove()
    {
        if (characterController.isGrounded)
        {
            player_MoveVector   = Vector3.zero;
            player_MoveVector.x = mobileController.Horizontal() * player_SpeedMove;
            player_MoveVector.z = mobileController.Vertical() * player_SpeedMove;
            if (Vector3.Angle(transform.forward, player_MoveVector) > 1f || Vector3.Angle(transform.forward, player_MoveVector) == 0f)
            {
                Vector3 direct = Vector3.RotateTowards(transform.forward, player_MoveVector, player_SpeedMove, 0.0f);
                transform.rotation = Quaternion.LookRotation(direct);
            }
        }
        //player_RigidBody.AddForce(((transform.right * mobileController.Horizontal() + (transform.forward * mobileController.Vertical())) * player_SpeedMove / Time.deltaTime));
        player_MoveVector.y = player_GravityForce;

        characterController.Move(player_MoveVector * Time.deltaTime);
    }
Exemple #12
0
    // Update is called once per frame
    void Update()
    {
        //float x = Input.GetAxisRaw("Horizontal");
        //float y = Input.GetAxisRaw("Vertical");
        float x = mContr.Horizontal();
        float y = mContr.Vertical();

        //float x = Input.acceleration.x;
        //float y = Input.acceleration.y - accelStartY/2;

        Vector2 direction = new Vector2(x, y);

        if (direction.sqrMagnitude > 1)
        {
            direction.Normalize();
        }

        Move(direction);
    }
Exemple #13
0
    public void FixedUpdate()
    {
        float motor    = maxMotorTorque * mCont.Vertical();
        float steering = maxSteeringAngle * mCont.Horizontal();

        foreach (AxleInfo axleInfo in axleInfos)
        {
            if (axleInfo.steering)
            {
                axleInfo.leftWheel.steerAngle  = steering;
                axleInfo.rightWheel.steerAngle = steering;
            }
            if (axleInfo.motor)
            {
                axleInfo.leftWheel.motorTorque  = motor;
                axleInfo.rightWheel.motorTorque = motor;
            }
            ApplyLocalPositionToVisuals(axleInfo.leftWheel);
            ApplyLocalPositionToVisuals(axleInfo.rightWheel);
        }
    }
    private void CharacterMove()
    {
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal() * speedMove;
        moveVector.z = mContr.Vertical() * speedMove;


        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        if (!ch_controller.isGrounded)
        {
            //transform.position.y -= 100 * Time.deltaTime;
            moveVector.y -= 400 * Time.deltaTime;
            // transform.position = new Vector3(transform.position.x, transform.position.y - 1 * Time.deltaTime, transform.position.z);
        }

        ch_controller.Move(moveVector * Time.deltaTime);
    }
Exemple #15
0
    void CharacterMove()
    {
        if (moveVector.x != 0 || moveVector.z != 0)
        {
            animator.SetBool("Move", true);
        }
        else
        {
            animator.SetBool("Move", false);
        }
        moveVector   = Vector3.zero;
        moveVector.x = mobileController.Horizontal() * speedMove;
        moveVector.z = mobileController.Vertical() * speedMove;

        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }

        moveVector.y = gravityForce;
        characterController.Move(moveVector * Time.deltaTime);
    }
    private void CharacterMove()
    {
        moveVector   = Vector3.zero;
        moveVector.x = mContr.Horizontal() /*Input.GetAxis("Horizontal")*/ * speedMove;
        moveVector.z = mContr.Vertical() /*Input.GetAxis("Vertical")*/ * speedMove;

        if (moveVector.x != 0 || moveVector.z != 0)
        {
            ch_animator.SetBool("Walk", true);
        }
        else
        {
            ch_animator.SetBool("Walk", false);
        }

        if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
        {
            Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
            transform.rotation = Quaternion.LookRotation(direct);
        }
        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime);
    }
    // Метод перемещения персонажа - джойстик 1
    private void CharacterMove()
    {
        // Отслеживаем кувырок
        if (isRoll)
        {
            timer += Time.deltaTime;
            if (timer >= timeRoll)
            {
            }
            else
            {
                ch_controller.Move(transform.forward * 5f * Time.deltaTime);
                return;
            }
        }

        // Отключаем перемещение в прыжке
        if (ch_controller.isGrounded)
        {
            ch_animator.ResetTrigger("isJump");
            ch_animator.SetBool("isFalling", false);

            float crouchSpeed = 1f;
            float runSpeed    = 1f;

            // Скорость в приседе or // Скорость в беге
            crouchSpeed = (crouchWalk) ? 3 : 1;
            runSpeed    = (isRun && !crouchWalk) ? 2.5f : 1;

            // Перемещение по поверхности
            moveVector   = Vector3.zero;
            moveVector.x = mContr.Horizontal() * (speedMove / crouchSpeed) * runSpeed;
            moveVector.z = mContr.Vertical() * (speedMove / crouchSpeed) * runSpeed;

            if (!crouchWalk)
            {
                ch_animator.SetBool("isCrouchWalk", false);

                // Анимация передвижения персонажа стоя
                if (moveVector.x != 0 || moveVector.z != 0)
                {
                    ch_animator.SetBool("isWalk", true);
                }
                else
                {
                    ch_animator.SetBool("isWalk", false);
                }
            }
            else
            {
                // Уменьшаем размеры персонажа когда он сидит
                ch_controller.center = new Vector3(0f, 0.57f, 0f);
                ch_controller.height = 1.2f;

                ch_animator.SetBool("isWalk", false);

                // Анимация передвижения персонажа в присиде
                if (moveVector.x != 0 || moveVector.z != 0)
                {
                    ch_animator.SetBool("isCrouchWalk", true);
                }
                else
                {
                    ch_animator.SetBool("isCrouchWalk", false);
                }
            }

            if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
            {
                Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
                transform.rotation = Quaternion.LookRotation(direct);
            }
        }
        else
        {
            if (gravityForce < -3f)
            {
                ch_animator.SetBool("isFalling", true);
            }
        }

        moveVector.y = gravityForce;
        ch_controller.Move(moveVector * Time.deltaTime);         // Метод передвижения по направлению
    }