Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Update() {
- wasGrounded = (ground != null);
- ground = groundCheck();
- walls = wallCheck();
- Vector2 targetMovement = new Vector2(rb.velocity.x, rb.velocity.y - gravityScale);
- if(ground != null && ground.GetComponent<Rigidbody2D>() != null) {
- targetMovement = new Vector2(rb.velocity.x + (ground.GetComponent<Rigidbody2D>().velocity.x * 0.425f), rb.velocity.y - gravityScale);
- }
- int horizontalInput = (int)Mathf.Round(Input.GetAxisRaw("Horizontal"));
- int verticalInput = (int)Mathf.Round(Input.GetAxisRaw("Vertical"));
- bool jumping = (verticalInput > 0f || Input.GetButton("Jump"));
- targetMovement.x = Mathf.Lerp(targetMovement.x, horizontalInput * movementSpeed, (!Mathf.Approximately(horizontalInput,0f))?moveFriction:groundFriction);
- if(jumping && ground != null && Time.time - lastJump >= jumpFreezeTime) {
- lastJump = Time.time;
- targetMovement.y = jumpPower;
- }
- currentMovement = targetMovement;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement