Jumping not working?

Hi can I have some guide on the jumping script below? I attached it to my player but whenever I press on space, the character does not move at all…

using UnityEngine;
using System.Collections;

public class Jumping : MonoBehaviour {
    private bool isJumping;
    private Vector2 force;
    // Use this for initialization
    void Start () {
        isJumping = false;
        force = new Vector2 (0.0f, 0.2f);
    }
   
    // Update is called once per frame
    void Update () {
        //Button of choice to jump
        if(Input.GetKey(KeyCode.Space))
        {
            if(isJumping == false)
            {
                rigidbody2D.AddForce (force);
                isJumping = true;
            }
        }
    }
   
    void OnCollisionEnter2D(Collision2D col)
    {
        //The floor is tagged as Ground
        if (col.gameObject.tag == "Ground")
        {
            //Logs to console, to check if working. *No problem here
            Debug.Log ("Working!");
            isJumping = false;
        }
    }
}

try add more force on y-axe force = new Vector2 (0.0f, 500f); if it not working, then make isJumping public, so you can check if it works good.

1 Like

Adding more force does work. Thanks a bunch!