Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update ()
- {
- //if (canMove)
- InputMovement();
- AnimationUpdate();
- //PixelSnapping();
- }
- void InputMovement()
- {
- if (rewiredPlayer.GetButton("Sprint"))
- currentMovementSpeed = pData.sprintSpeed;
- else
- currentMovementSpeed = pData.movementSpeed;
- if (controllerInput == false) //If using keyboard controls
- {
- //Get the movement key value input
- verticalInput = rewiredPlayer.GetAxisRaw("Move Vertical");
- horizontalInput = rewiredPlayer.GetAxisRaw("Move Horizontal");
- if (canMove == true)
- {
- if (verticalInput != 0 || horizontalInput != 0)
- {
- //Set the velocity based on the input direction.
- playerRBody.velocity = (new Vector2(horizontalInput, verticalInput).normalized * currentMovementSpeed);
- }
- else if (playerRBody.velocity != Vector2.zero) //else if we're still moving and not pressing any movement keys
- {
- playerRBody.velocity = Vector2.zero;
- }
- }
- if (GetComponentInChildren<CamPanningScript>().controllerInput != false)
- GetComponentInChildren<CamPanningScript>().controllerInput = false;
- }
- else //Using controller input
- {
- //Get the movement key value input
- verticalInput = rewiredPlayer.GetAxis("Move Vertical");
- horizontalInput = rewiredPlayer.GetAxis("Move Horizontal");
- if (canMove == true)
- {
- //If we're pressing any movement keys
- if (verticalInput != 0 || horizontalInput != 0)
- {
- //Set the velocity based on the input direction.
- playerRBody.velocity = (new Vector2(horizontalInput, verticalInput) * currentMovementSpeed);
- }
- else if (playerRBody.velocity != Vector2.zero) //else if we're still moving and not pressing any movement keys
- {
- playerRBody.velocity = Vector2.zero;
- }
- }
- if (GetComponentInChildren<CamPanningScript>().controllerInput != true)
- GetComponentInChildren<CamPanningScript>().controllerInput = true;
- }
- }
- void AnimationUpdate()
- {
- facingDirection = new Vector2(horizontalInput, verticalInput).normalized;
- if (canMove)
- {
- if (verticalInput != 0 || horizontalInput != 0)
- {
- animController.SetBool("isMoving", true);
- animController.SetFloat("horizontal", Mathf.Round(facingDirection.x));
- animController.SetFloat("vertical", Mathf.Round(facingDirection.y));
- }
- else
- {
- animController.SetBool("isMoving", false);
- }
- }
- //animController.SetFloat("horizontal", horizontalInput);
- //animController.SetFloat("vertical", verticalInput);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement