コード例 #1
0
ファイル: PlayerLocomotion.cs プロジェクト: kenttim/MAGD488
    public void HandleMovement(float delta)
    {
        if (inputHandler.rollFlag) //sprinting stuff
        {
            return;
        }

        if (playerManager.isInteracting) // fall stuff
        {
            return;
        }

        moveDirection  = cameraObject.forward * inputHandler.vertical;
        moveDirection += cameraObject.right * inputHandler.horizontal;
        moveDirection.Normalize();
        moveDirection.y = 0;

        float speed = movementSpeed;

        if (inputHandler.sprintFlag && inputHandler.moveAmount > 0.5) //sprinting stuff
        {
            speed = sprintSpeed;
            playerManager.isSprinting = true;
            moveDirection            *= speed;
        }
        else
        {
            if (inputHandler.moveAmount < .5)
            {
                moveDirection            *= movementSpeed;
                playerManager.isSprinting = false;
            }
            else
            {
                moveDirection            *= speed;
                playerManager.isSprinting = false;
            }
        } //sprinting stuff

        Vector3 projectedVelocity = Vector3.ProjectOnPlane(moveDirection, normalVector);

        rigidbody.velocity = projectedVelocity;

        //when animations are added                                     //sprinting stuff
        animatorHandler.UpdateAnimatorValues(inputHandler.moveAmount, 0, playerManager.isSprinting);

        if (animatorHandler.canRotate)
        {
            HandleRotation(delta);
        }
    }
コード例 #2
0
        public void Update()
        {
            float delta = Time.deltaTime;

            inputHadler.TickInput(delta);
            //moveDirection = cameraObject.forward * inputHadler.vertical;
            //moveDirection += cameraObject.right * inputHadler.horizontal;
            moveDirection = -transform.right * inputHadler.vertical + transform.forward * inputHadler.horizontal;
            moveDirection.Normalize();

            float speed = movementSpeed;

            moveDirection  *= speed;
            moveDirection.y = rigidbody.velocity.y;
            Vector3 projectedVelocity = Vector3.ProjectOnPlane(moveDirection, normalVector);

            rigidbody.velocity = projectedVelocity;
            //Debug.Log(inputHadler.horizontal + "H");
            // Debug.Log(inputHadler.vertical  + "V");

            if (inputHadler.horizontal < 0.0f)
            {
                child.transform.rotation = Quaternion.Euler(new Vector3(0, -180, 0));
            }
            if (inputHadler.horizontal > 0.0f)
            {
                child.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
            }
            if (inputHadler.vertical < 0.0f)
            {
                child.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
            }
            if (inputHadler.vertical > 0.0f)
            {
                child.transform.rotation = Quaternion.Euler(new Vector3(0, -90, 0));
            }
            animatorHandler.UpdateAnimatorValues(inputHadler.moveAmount, 0);
            //if (animatorHandler.canRotate)
            // HandleRotation(delta);

            if (inputHadler.horizontal != 0.0f)
            {
                precMovX = inputHadler.horizontal > 0.0f ?  true : false;
            }
            if (inputHadler.vertical != 0.0f)
            {
                precMovY = inputHadler.vertical > 0.0f ?  true : false;
            }
        }
コード例 #3
0
    public void HandleMovement(float delta)
    {
        if (isJumping)//salto estatico
        {
            return;
        }

        if (inputHandler.rollflag) //si hace roll salirse de esta funcion
        {
            return;
        }

        if (playerManager.isInteracting)
        {
            return;
        }

        moveDirection  = cameraObject.forward * inputHandler.vertical;
        moveDirection += cameraObject.right * inputHandler.horizontal;
        moveDirection.Normalize();
        moveDirection.y = 0;

        float speed = movementSpeed;

        //si pulsa sprint y tiene stamina suficiente
        if (inputHandler.sprintflag && inputHandler.moveAmount > 0.5 && playerStats.currentStamina > 0) //si hace sprint
        {
            speed = sprintSpeed;
            playerManager.isSprinting = true;
            moveDirection            *= speed;
        }
        else
        {
            if (inputHandler.moveAmount < 0.5)
            {
                moveDirection            *= movementSpeed;
                playerManager.isSprinting = false;
            }
            else
            {
                moveDirection            *= speed;
                playerManager.isSprinting = false;
            }
        }


        Vector3 projectedVelocity = Vector3.ProjectOnPlane(moveDirection, normalVector);

        rigidbody.velocity = projectedVelocity;

        //animaciones modo enfoque
        if (inputHandler.lockOnFlag && inputHandler.sprintflag == false)
        { //SI ESTA EN MODO ENFOQUE y no esta en modo bola
            animatorHandler.UpdateAnimatorValues(inputHandler.vertical, inputHandler.horizontal, playerManager.isSprinting);
        }
        else
        { //sino
            animatorHandler.UpdateAnimatorValues(inputHandler.moveAmount, 0, playerManager.isSprinting);
        }



        if (animatorHandler.canRotate)
        {
            HandleRotation(delta);
        }
    }
コード例 #4
0
    public void HandleMovement(float delta)
    {
        if (inputHandler.rollFlag)
        {
            return;
        }

        //Disable the player control when the character is Interacting or doing certain things.
        if (playerManager.isInteracting)
        {
            return;
        }
        if (playerManager.isInAir)
        {
            return;
        }

        if (Input.GetKey(KeyCode.Tab))
        {
            animatorHandler.UpdateAnimatorValues(0, 0, false);
            rigidbody.velocity = Vector3.zero;
            return;
        }

        moveDirection  = cameraObject.forward * inputHandler.vertical;
        moveDirection += cameraObject.right * inputHandler.horizontal;
        moveDirection.Normalize();
        moveDirection.y = 0;

        float speed = movementSpeed;

        if (inputHandler.sprintFlag && inputHandler.moveAmount > 0.5f)
        {
            speed = sprintSpeed;
            playerManager.isSprinting = true;
            moveDirection            *= speed;
        }
        else
        {
            if (inputHandler.moveAmount < 0.5f)
            {
                moveDirection            *= speed;
                playerManager.isSprinting = false;
            }
            else
            {
                moveDirection            *= speed;
                playerManager.isSprinting = false;
            }
        }

        Vector3 projectedVelocity = Vector3.ProjectOnPlane(moveDirection, normalVector);

        rigidbody.velocity = projectedVelocity;

        animatorHandler.UpdateAnimatorValues(inputHandler.moveAmount, 0, playerManager.isSprinting);

        if (animatorHandler.canRotate)
        {
            HandleRotation(delta);
        }
    }