One thing I noticed, you wrote OnColliderEnter but it is supposed to say OnCollisionEnter and OnCollisionExit.
Also, the way this script is set up, the ‘jumping physics’ being applied to the object are only being applied per-frame. Because the jump is in the Update() function it only gets a split second to apply the physics force to the object, by the next frame, it has already stopped applying force to the object, and it then checks to see if the button is pressed again. (Input.GetButtonDown and Input.GetKeyDown get the ‘jump key’ only once when pressed and doesn’t matter if it is held down. Input.GetButton and Input.GetKey will return true as long as they are pressed.)
So the problem is that, to use AddForce to move an object in this way is not the best way for controlled jumps, it has a quick moment to apply the force, each Update frame, so it ‘sputters’ and quickly is no longer grounded and therefore not allowed to jump any further. A different way you could do this is to use an IEnumerator function for the ‘Jump’ (instead of Update()) because the physics force can be applied for a fixed period of time over several Update frames (unlike Update which operates frame by frame). You could also create a new Animation for the object and use the animation recorder to record a ‘jump movement’ animation that could just be played when the key is pressed (using Animation.Play). Anyways, here is your script below with the changed OnCollision stuff. I also changed the void Jump() function name so it wouldn’t conflict with the default Unity name for the ‘Jump’ button. I also changed the “JumpButton” to Unity’s default “Jump”. I added the J key (J as in Joker) as a jump button too, but it uses GetKey instead of GetKeyDown to show you the difference between J and SPACE, SPACE will jump(apply force) once per press, J will jump as long as J is pressed (and the object is grounded to jump).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerJump : MonoBehaviour {
public Rigidbody rb;
[Range (0.0f, 200.0f)]
public float JumpVelocity = 100.0f;
private bool isGrounded = true;
void Start () {
rb = GetComponent<Rigidbody>();
}
void Update () {
if (isGrounded == true) {
if (Input.GetKey(KeyCode.J) || (Input.GetButtonDown ("Jump"))) {
JumpUp ();
}
}
}
void JumpUp () {
Debug.Log(" JUMP " + transform.up * JumpVelocity + "");
rb.AddForce(Vector3.up * JumpVelocity);
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Ground") {
Debug.Log("COLLIDE Begin - isGrounded:" + isGrounded + "");
isGrounded = true;
}
}
void OnCollisionExit(Collision other) {
if (other.gameObject.tag == "Ground") {
Debug.Log("COLLIDE End - isGrounded:" + isGrounded + "");
isGrounded = false;
}
}
}