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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JumpingScript : 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.GetKeyDown(KeyCode.UpArrow))
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
Debug.Log("it works!");
}
}
}
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!