Advertisement
CakeMeister

Better Jumping

Dec 15th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Jumping : MonoBehaviour {
  6.  
  7.     public float fallgravity = 2.5f;
  8.     public float upgravity = 2f;
  9.  
  10.     Rigidbody2D r2d;
  11.  
  12.     void Start()
  13.     {
  14.         r2d = GetComponent<Rigidbody2D>();
  15.     }
  16.  
  17.     void Update()
  18.     {
  19.         if (r2d.velocity.y <0)
  20.         {
  21.             r2d.velocity += Vector2.up * Physics2D.gravity.y * (fallgravity - 1) * Time.deltaTime;
  22.         }
  23.         else if (r2d.velocity.y > 0 && !Input.GetKey(KeyCode.Space))
  24.         {
  25.             r2d.velocity += Vector2.up * Physics2D.gravity.y * (upgravity - 1) * Time.deltaTime;
  26.         }
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement