# Jumping problem (547091)

**URL:** https://discussions.unity.com/t/jumping-problem-547091/547091
**Category:** Scripting
**Tags:** Scripting
**Created:** [August 15, 2014, 7:40pm UTC](https://discussions.unity.com/t/jumping-problem-547091/547091 "2014-08-15T19:40:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![UnityUser\_721](https://avatars.discourse-cdn.com/v4/letter/u/278dde/32.png) [@UnityUser\_721](https://discussions.unity.com/u/UnityUser_721)
#### Post date: [August 15, 2014, 7:40pm UTC](https://discussions.unity.com/t/jumping-problem-547091/547091/1 "2014-08-15T19:40:09Z")

</div>

I have this script that needs to make the sphere jump:

```csharp
using UnityEngine;
using System.Collections;

public class MoveSphere : MonoBehaviour {

    private float MovementSpeed = 2;
    private bool isFalling = false;
    private float JumpForce = 2;
    public GameObject JumpOnOtherThenWall;
   
    void Update()
    {
        float MoveHorizontal = Input.GetAxis ("Horizontal");
        Vector3 Movement = new Vector2(MoveHorizontal, 0.0f);
        rigidbody.AddForce(-Movement * MovementSpeed);

        //Jump
        if(Input.GetKeyDown (KeyCode.Space) && isFalling == false)
        {
            rigidbody.AddForce(Vector3.up * JumpForce * 100);
        }
        isFalling = true;
    }

    //Jump only if on the ground
    void OnCollisionStay()
    {
        if(JumpOnOtherThenWall.name != "Wall")
        {
            isFalling = false;
        }
    }

}

```

The problem is that it allows the player to jump even if the player is touching the wall and not the floor, I added the if statement inside the OnCollisionStay() function in order to prevent that but now it’s not jumping at all.

---

<div class="post-metadata">

### Author: ![roger0](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@roger0](https://discussions.unity.com/u/roger0)
#### Post date: [August 15, 2014, 10:04pm UTC](https://discussions.unity.com/t/jumping-problem-547091/547091/2 "2014-08-15T22:04:13Z")

</div>

I think its because isFalling is being set to false constantly in the update function, and its overriding the OnCollisionStay function.

---

<div class="post-metadata">

### Author: ![UnityUser\_721](https://avatars.discourse-cdn.com/v4/letter/u/278dde/32.png) [@UnityUser\_721](https://discussions.unity.com/u/UnityUser_721)
#### Post date: [August 15, 2014, 10:15pm UTC](https://discussions.unity.com/t/jumping-problem-547091/547091/3 "2014-08-15T22:15:20Z")

</div>

It is set to true not false and the only thing that does the problem is the if in the OnCollisionStay, it worked without it but like I said it was possible to jump on walls 😕
