cube jump - script not working and with no errors

hello
I’m making an endless runner kinda thing there’s the problem:
the cube jumps just one time and then it doesn’t jump at all when it fall in the next tile / ground
Any help ??

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
    
    public float speed = 15.0F;
	private Rigidbody rb;
    public Vector3 jump;
    public float jumpForce = 2.0f;
    public bool isGrounded;

    //Use this for initialization
    void Start () {
		rb = GetComponent<Rigidbody>();
        jump = new Vector3(0.0f, 2.0f, 0.0f);
    }
	
	// Update is called once per frame
	void Update () {
		transform.Translate (Vector3.forward * (speed) * Time.deltaTime);

        if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {

            rb.AddForce(jump * jumpForce, ForceMode.Impulse);
            isGrounded = false;
        }
    }
}

1 Answer

1

Your not setting IsGrounded to true when you land. You could do this with this code:

void OnCollisionEnter(Collision col)
{
    if (col.gameObject.name == "insert platform object name here")
    {
        isGrounded = true
    }
}

Hope this helps!

I did as you said and I did a different one as well to test it still jumps in the first time and then nothing, the ground be true just in the first time and then turns false for ever :( > void onCollisionEnter(Collision other) { if(other.gameObject.CompareTag("Ground")) { isGround = true; } }