Exemple #1
0
    private void Move()
    {
        Vector3 moveDirection = transform.InverseTransformDirection(xzMove.normalized);

        animator.SetFloat("MoveForward", moveDirection.z);
        animator.SetFloat("MoveRight", moveDirection.x);

        float velocity = 0f;

        velocity += backwardSpeed * Mathf.Clamp(moveDirection.z, -1, 0);
        velocity += forwardSpeed * Mathf.Clamp(moveDirection.z, 0, 1);
        velocity += sideSpeed * moveDirection.x;

        #region debug
        //string debugVelocity = "";
        //debugVelocity += "Backward=" + backwardSpeed * Mathf.Clamp(v.z, -1, 0);
        //debugVelocity += "  Forward=" + forwardSpeed * Mathf.Clamp(v.z, 0, 1);
        //debugVelocity += "  Side=" + sideSpeed * v.x;
        //Debug.Log(debugVelocity);
        #endregion

        float factor = 1;
        #region debug
        if (Input.GetKey(KeyCode.CapsLock))
        {
            factor = walkFactor;
        }
        else if (Input.GetKey(KeyCode.LeftShift))
        {
            factor = sprintFactor;
        }
        #endregion
        velocity     *= factor;
        moveMagnitude = Mathf.Clamp(xzMove.magnitude, 0, 1f) * factor;
        animator.SetFloat("InputMagnitude", moveMagnitude, animSmooth, Time.deltaTime);

        //Apply movement
        controller.Move(yMove * Time.deltaTime);
        controller.Move(xzMove.normalized * Time.deltaTime * Mathf.Abs(velocity));
    }
Exemple #2
0
    private void Move()
    {
        if (canMove)
        {
            //Get xzMove in local coordinates
            Vector3 moveDirection = transform.InverseTransformDirection(xzMove.normalized);

            animator.SetFloat("MoveForward", moveDirection.z);
            animator.SetFloat("MoveRight", moveDirection.x);

            moveMagnitude = Mathf.Clamp(xzMove.magnitude, 0, 1f);
            animator.SetFloat("InputMagnitude", moveMagnitude, animSmooth, Time.deltaTime);

            //Apply movement
            controller.Move(yMove * Time.deltaTime);
            controller.Move(xzMove.normalized * Time.deltaTime * speed);
        }
        else
        {
            animator.SetFloat("MoveForward", 0);
            animator.SetFloat("MoveRight", 0);
            animator.SetFloat("InputMagnitude", 0);
        }
    }