Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created January 15, 2018 05:55
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 pkulev/79ac4e8d35d557f5e848a8f0dc2a721d to your computer and use it in GitHub Desktop.
Save pkulev/79ac4e8d35d557f5e848a8f0dc2a721d to your computer and use it in GitHub Desktop.
Not physically ideal but good jump
using UnityEngine;
using System.Collections;
public class GravityJump : MonoBehaviour {
public float fallMultiplier = 2.5f;
public float lowJumpMultiplier = 2f;
Rigidbody2D rb;
void Awake() {
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