Advertisement
Guest User

Better jump

a guest
Aug 19th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BetterJump : MonoBehaviour
  6. {
  7.     private Rigidbody2D rb;
  8.     public float fallMultiplier = 2.5f;
  9.     public float lowJumpMultiplier = 2f;
  10.  
  11.     void Start()
  12.     {
  13.         rb = GetComponent<Rigidbody2D>();
  14.     }
  15.  
  16.     void Update()
  17.     {
  18.         if (rb.velocity.y < 0)
  19.         {
  20.             rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
  21.         }
  22.         else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
  23.         {
  24.             rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement