Search Unity

Jump not working?

Discussion in '2D' started by bennettyu82, Mar 3, 2021.

  1. bennettyu82

    bennettyu82

    Joined:
    Aug 17, 2020
    Posts:
    5
    I've recently started to make a 2D platformer game. I got the character to move around by using the A and D keys, but then when I started to follow some tutorials on how to make the character jump, none of them would work! Here is the code for my current jump program.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class JumpingScript : MonoBehaviour
    6. {
    7.     public float fallMultiplier = 2.5f;
    8.     public float lowJumpMultiplier = 2f;
    9.  
    10.     Rigidbody2D rb;
    11.  
    12.     void Awake()
    13.     {
    14.         rb = GetComponent<Rigidbody2D>();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if (rb.velocity.y < 0)
    20.         {
    21.             rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
    22.         } else if(rb.velocity.y > 0 && !Input.GetKeyDown(KeyCode.UpArrow))
    23.         {
    24.             rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
    25.             Debug.Log("it works!");
    26.         }
    27.     }
    28. }
    29.  
    I made the key to jump the up arrow and even made a debug log tester. The tester worked, so whenever I pressed the up arrow it would say "it works!" in the console, but my character would not jump. Any help is greatly appreciated!
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465


    This video is great for newbies. It will give you a foundation to build off of.
     
  3. bennettyu82

    bennettyu82

    Joined:
    Aug 17, 2020
    Posts:
    5
    Thank you so much!