Skip to content

Instantly share code, notes, and snippets.

@mrhammadasif
Created December 15, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrhammadasif/cf80b34a81f93ff07b0e0bb2ee90b6d4 to your computer and use it in GitHub Desktop.
Save mrhammadasif/cf80b34a81f93ff07b0e0bb2ee90b6d4 to your computer and use it in GitHub Desktop.
BetterJump in Unity
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