Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1.     void Update ()
  2.     {
  3.         //if (canMove)
  4.             InputMovement();
  5.  
  6.         AnimationUpdate();
  7.         //PixelSnapping();
  8.     }
  9.  
  10.     void InputMovement()
  11.     {
  12.         if (rewiredPlayer.GetButton("Sprint"))
  13.             currentMovementSpeed = pData.sprintSpeed;
  14.         else
  15.             currentMovementSpeed = pData.movementSpeed;
  16.  
  17.         if (controllerInput == false) //If using keyboard controls
  18.         {
  19.             //Get the movement key value input
  20.             verticalInput = rewiredPlayer.GetAxisRaw("Move Vertical");
  21.             horizontalInput = rewiredPlayer.GetAxisRaw("Move Horizontal");
  22.  
  23.             if (canMove == true)
  24.             {
  25.                 if (verticalInput != 0 || horizontalInput != 0)
  26.                 {
  27.                     //Set the velocity based on the input direction.
  28.                     playerRBody.velocity = (new Vector2(horizontalInput, verticalInput).normalized * currentMovementSpeed);
  29.  
  30.                 }
  31.                 else if (playerRBody.velocity != Vector2.zero) //else if we're still moving and not pressing any movement keys
  32.                 {
  33.                     playerRBody.velocity = Vector2.zero;
  34.                 }
  35.             }
  36.  
  37.             if (GetComponentInChildren<CamPanningScript>().controllerInput != false)
  38.                 GetComponentInChildren<CamPanningScript>().controllerInput = false;
  39.         }
  40.         else //Using controller input
  41.         {
  42.             //Get the movement key value input
  43.             verticalInput = rewiredPlayer.GetAxis("Move Vertical");
  44.             horizontalInput = rewiredPlayer.GetAxis("Move Horizontal");
  45.  
  46.             if (canMove == true)
  47.             {
  48.                 //If we're pressing any movement keys
  49.                 if (verticalInput != 0 || horizontalInput != 0)
  50.                 {
  51.                     //Set the velocity based on the input direction.
  52.                     playerRBody.velocity = (new Vector2(horizontalInput, verticalInput) * currentMovementSpeed);
  53.                 }
  54.                 else if (playerRBody.velocity != Vector2.zero) //else if we're still moving and not pressing any movement keys
  55.                 {
  56.                     playerRBody.velocity = Vector2.zero;
  57.                 }
  58.             }
  59.             if (GetComponentInChildren<CamPanningScript>().controllerInput != true)
  60.                 GetComponentInChildren<CamPanningScript>().controllerInput = true;
  61.         }
  62.     }
  63.  
  64.     void AnimationUpdate()
  65.     {
  66.         facingDirection = new Vector2(horizontalInput, verticalInput).normalized;
  67.  
  68.         if (canMove)
  69.         {
  70.             if (verticalInput != 0 || horizontalInput != 0)
  71.             {
  72.                 animController.SetBool("isMoving", true);
  73.  
  74.                 animController.SetFloat("horizontal", Mathf.Round(facingDirection.x));
  75.                 animController.SetFloat("vertical", Mathf.Round(facingDirection.y));
  76.             }
  77.             else
  78.             {
  79.                 animController.SetBool("isMoving", false);
  80.             }
  81.         }
  82.  
  83.         //animController.SetFloat("horizontal", horizontalInput);
  84.         //animController.SetFloat("vertical", verticalInput);
  85.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement