- Home /
Question by
santinoheybusiness · Jan 23, 2021 at 06:07 PM ·
2dunity 2d2d-platformerjumpjumping
Im trying to make it so it limits jumps in my 2d game. But when I play it, It only jumps once then your not able to jump again. Anyhelp? I need a answer fast because this is for the blackthornprod game jam
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
public float Jump;
private float move;
private Rigidbody2D rb;
private bool isJumping;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
move = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(move * speed, rb.velocity.y);
if (Input.GetButtonDown("Jump") && !isJumping)
{
rb.AddForce(new Vector2(rb.velocity.x, Jump));
isJumping = true;
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Ground"))
{
isJumping = false;
}
}
}
Comment
Answer by santinoheybusiness · Jan 23, 2021 at 06:32 PM
@Bunny83 @fafase @Mike 3 @Statement @duck @whydoidoit @robertbu can any of you help me, please?
Answer by RealFolk · Jan 23, 2021 at 06:38 PM
Your code is fine. You probably forgot to tag your ground as "Ground".
i just realized i tagged the player and not the ground smh, thanks btw!
Your answer
Follow this Question
Related Questions
Problem with Jump 1 Answer
Raycast2D not working 1 Answer
Unity 2D player sticks on platform corners 2 Answers
how can I make the character jump more by holding the jump button in this script? 1 Answer
Help with a 2d camera Controller 1 Answer