Created
December 15, 2017 13:29
-
-
Save mrhammadasif/cf80b34a81f93ff07b0e0bb2ee90b6d4 to your computer and use it in GitHub Desktop.
BetterJump in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class BetterJump : MonoBehaviour { | |
public float FallMultiplier = 2.5f; | |
public float lowJumpMultiplier = 2f; | |
RigidBody2D rb; | |
void Start() { | |
rb = GetComponent<RigidBody2D>(); | |
} | |
void Update() { | |
if (rb.velocity.y < 0) { | |
rb.velocity += Vector2.up * Physics2D.gravity.y * (FallMultiplier - 1) * Time.deltaTime; | |
} else if (rb.velocity.y > 0 && !Input.GetButton("Jump")) { | |
rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment