Why Doesn't my charecter jump.

This is The Code That I have been using. It works on every thing else. like moving left or right(I’m Using unity 2019.4.20f1 )

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{

public LayerMask whatIsGround;
public Transform groundCheck;
public bool isGrounded;
public float jumpForce;
public float speed;
Rigidbody2D rb;

void Start ()
{
    rb = GetComponent <Rigidbody2D> ();
}

void Update () {
    if (Input.GetButtonDown ("Jump") && isGrounded) {
        rb.AddForce (Vector2.up * jumpForce, ForceMode2D.Impulse);
        isGrounded = false;
    }
}

void FixedUpdate ()
{
    isGrounded = Physics2D.OverlapPoint (groundCheck.position, whatIsGround);
    float x = Input.GetAxis ("Horizontal");
    Vector3 move = new Vector3 (x * speed, rb.velocity.y, 0f);
    rb.velocity = move;
}

}

1 Answer

1

@piiroineo there could be few reasons this could be happening

  1. The mass of your gameobject is way too higher in respect to your jump force or the jump thrust may not be sufficient enough try increasing the force to very large numbers to see if it works or not

2.Try removing the IsGrounded parameter from if statement just to be sure that it’s not messing up as you have used Phyics2D.overlapPoint rather than Phyics2D.OverlapCircleAll.

  1. Make sure under rigidbody component in constraints y position is not checked

  2. Make sure your rigidbody type is dynamic and not static

Handy Tip: For current case ForceMode2D.Force will better over ForceMode2D.Impulse