Advertisement
NeoGriever

Untitled

Oct 9th, 2020
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.   void Update() {
  2.     wasGrounded = (ground != null);
  3.     ground = groundCheck();
  4.     walls = wallCheck();
  5.  
  6.     Vector2 targetMovement = new Vector2(rb.velocity.x, rb.velocity.y - gravityScale);
  7.  
  8.     if(ground != null && ground.GetComponent<Rigidbody2D>() != null) {
  9.       targetMovement = new Vector2(rb.velocity.x + (ground.GetComponent<Rigidbody2D>().velocity.x * 0.425f), rb.velocity.y - gravityScale);
  10.     }
  11.  
  12.     int horizontalInput = (int)Mathf.Round(Input.GetAxisRaw("Horizontal"));
  13.     int verticalInput = (int)Mathf.Round(Input.GetAxisRaw("Vertical"));
  14.     bool jumping = (verticalInput > 0f || Input.GetButton("Jump"));
  15.  
  16.     targetMovement.x = Mathf.Lerp(targetMovement.x, horizontalInput * movementSpeed, (!Mathf.Approximately(horizontalInput,0f))?moveFriction:groundFriction);
  17.     if(jumping && ground != null && Time.time - lastJump >= jumpFreezeTime) {
  18.       lastJump = Time.time;
  19.       targetMovement.y = jumpPower;
  20.     }
  21.  
  22.     currentMovement = targetMovement;
  23.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement