Created
January 15, 2018 05:55
-
-
Save pkulev/79ac4e8d35d557f5e848a8f0dc2a721d to your computer and use it in GitHub Desktop.
Not physically ideal but good jump
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 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